Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dapp tests - update contract deployment #1874

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/test/ERC20toCW20PointerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe("ERC20 to CW20 Pointer", function () {
const owner = accounts[0].evmAddress;
const spender = accounts[1].evmAddress;
const blockNumber = await ethers.provider.getBlockNumber();
const tx = await pointer.approve(spender, 1000000);
const tx = await pointer.approve(spender, 1000000, {gasPrice: (await ethers.provider.getFeeData()).gasPrice});
const receipt = await tx.wait();
const allowance = await pointer.allowance(owner, spender);
expect(Number(allowance)).to.equal(1000000);
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/EVMCompatabilityTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe("EVM Test", function () {

await delay()
// Call balanceOf using callAnotherContract from EVMCompatibilityTester
await evmTester.callAnotherContract(tokenAddress, balanceOfData);
await evmTester.callAnotherContract(tokenAddress, balanceOfData, {gasPrice: (await ethers.provider.getFeeData()).gasPrice});

await delay()
// Verify the balance using MyToken contract directly
Expand Down
5 changes: 5 additions & 0 deletions integration_test/dapp_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ On the test pipelines, the account used is:
- Deployer Sei address: `sei1rtpakm7w9egh0n7xngzm6vrln0szv6yeva6hhn`
- Deployer EVM address: `0x4D952b770C3a0B096e739399B40263D0b516d406`

The tests can be ran against already deployed contracts on arctic-1 or on clusters. For arctic-1 the contract addresses are already stored on config directory.
For cluster tests, tests first deploy the contracts and store addresses in a new json created in config directory. For the next
iterations the tests are going to use these addresses. To run the tests against node cluster, update the endpoints on constants.js file.

To run the tests you can simply pass `-f` flag into the command.
## Tests

### Uniswap (EVM DEX)
Expand Down
6 changes: 6 additions & 0 deletions integration_test/dapp_tests/configs/nftConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"marketplace": "0x305E8dc769aae003c17fB08b9cc9108Cb4630E79",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these constants or different for each chain?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are for the arctic 1, and already deployed. I didnt create another config for atlantic-2, on the basis that they should be identical but I can deploy and create another config for atlantic 2 as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha, just wanted to make sure it would be identical on atlantic-2

"erc721token": "0x8Ee23935ca017dbe78Fc72b74C90F9FCF4e2f9E5",
"cw721Address": "sei1tpz0rk984996x87sgmzr0te7n4p2j9r8vq7pqq0psf0l7642ze2qx9wzsf",
"erc721PointerToken": "0xC88F617fa5943466437f7ce03aaE8779ae083847"
}
5 changes: 5 additions & 0 deletions integration_test/dapp_tests/configs/steakConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hubAddress": "sei1dynepqqjm6u4prcvdyh5qlhrglld78xy7pa4w05gq9vas4ws3e4q7dmyff",
"tokenAddress": "sei1v7gfan5kjry9aqs2l6z0smx4cj2kgcz5ngmd09caex5y7ucr9yqq6pth9d",
"pointerAddress": "0x505868BB5Babd68D84D96bbc0851062C6cF0619a"
}
10 changes: 10 additions & 0 deletions integration_test/dapp_tests/configs/uniswapConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"manager": "0xcE11491995E05b947820836aecE9D7A5Fcdaeb01",
"router": "0x0c086805476d29b306ffF178B53176565F880893",
"erc20TokenFactory": "0x7e3378bcEad49Bbfc8D9024657c942d44f1A1a94",
"erc20cw20": "0x7E7095dfB469A39CF6C67554A8896314D6B0567F",
"weth9": "0x5cA05f8eA1a25d74eBD222a9Ea3730c82B4082A4",
"token": "0xB73a15C476A9D14d57162472527e3FbFdF21dE3F",
"tokenFactoryDenom": "factory/sei1ak5ztcchehv2gy64yxpcdnftepnacvwgxwwfzw/dappTests1727707705418",
"cw20Address": "sei127nvmtnn3tkt6xxgss2z4n0exgm043sc0e2na5lca7h3n4qxs8us4rykxp"
}
12 changes: 9 additions & 3 deletions integration_test/dapp_tests/constants.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
const rpcUrls = {
"seilocal": "http://127.0.0.1:26657",
"testnet": "https://rpc-testnet.sei-apis.com",
"devnet": "https://rpc-arctic-1.sei-apis.com"
"devnet": "https://rpc-arctic-1.sei-apis.com",
"seiCluster": "http://127.0.0.1:26657"
}

const evmRpcUrls = {
"seilocal": "http://127.0.0.1:8545",
"testnet": "https://evm-rpc-testnet.sei-apis.com",
"devnet": "https://evm-rpc-arctic-1.sei-apis.com"
"devnet": "https://evm-rpc-arctic-1.sei-apis.com",
"seiCluster": "http://127.0.0.1:8545"
}

const chainIds = {
"seilocal": "sei",
"testnet": "atlantic-2",
"devnet": "arctic-1"
"devnet": "arctic-1",
"seiCluster":"sei-chain",
}

module.exports = {
Expand Down
12 changes: 12 additions & 0 deletions integration_test/dapp_tests/dapp_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ if [ -z "$1" ]; then
exit 1
fi

IS_FAST_TRACK=false

# Check if -fast track enabled is present
for arg in "$@"; do
if [[ "$arg" == "-f" ]]; then
IS_FAST_TRACK=true
break
fi
done

export IS_FAST_TRACK

set -e

# Define the paths to the test files
Expand Down
9 changes: 9 additions & 0 deletions integration_test/dapp_tests/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ module.exports = {
networks: {
seilocal: {
url: "http://127.0.0.1:8545",
accounts: {
mnemonic: "potato beach spawn early pole peanut insect bus addict orient camp refuse news robust drive napkin race summer toss oppose cream grit gadget clever",
path: "m/44'/118'/0'/0/0",
initialIndex: 0,
count: 1
},
},
seiCluster: {
url: "",
accounts: {
mnemonic: process.env.DAPP_TESTS_MNEMONIC,
path: "m/44'/118'/0'/0/0",
Expand Down
72 changes: 25 additions & 47 deletions integration_test/dapp_tests/nftMarketplace/nftMarketplaceTests.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,44 @@
const { expect } = require("chai");
const hre = require("hardhat");

const {sendFunds, deployEthersContract, estimateAndCall, deployCw721WithPointer, setupAccountWithMnemonic,
mintCw721
const {
sendFunds, estimateAndCall, mintCw721, deployAndReturnContractsForNftTests,
queryLatestNftIds, setDaemonConfig
} = require("../utils");
const { fundAddress, getSeiAddress, execute } = require("../../../contracts/test/lib.js");
const {evmRpcUrls, chainIds, rpcUrls} = require("../constants");
const { getSeiAddress, execute } = require("../../../contracts/test/lib.js");

const testChain = process.env.DAPP_TEST_ENV;
console.log("testChain", testChain);
describe("NFT Marketplace", function () {
const isFastTrackEnabled = process.env.IS_FAST_TRACK;

let marketplace, deployer, erc721token, erc721PointerToken, cw721Address, originalSeidConfig;
describe("NFT Marketplace", function () {
console.log('NFT Tests are being run');
let marketplace, deployer, erc721token, erc721PointerToken, cw721Address, originalSeidConfig, nftId1;

before(async function () {
const accounts = hre.config.networks[testChain].accounts
const deployerWallet = hre.ethers.Wallet.fromMnemonic(accounts.mnemonic, accounts.path);
deployer = deployerWallet.connect(hre.ethers.provider);
originalSeidConfig = await setDaemonConfig(testChain);

const seidConfig = await execute('seid config');
originalSeidConfig = JSON.parse(seidConfig);

if (testChain === 'seilocal') {
await fundAddress(deployer.address, amount="2000000000000000000000");
} else {
// Set default seid config to the specified rpc url.
await execute(`seid config chain-id ${chainIds[testChain]}`)
await execute(`seid config node ${rpcUrls[testChain]}`)
}

await execute(`seid config keyring-backend test`)
({
marketplace,
erc721token,
cw721Address,
erc721PointerToken
} = await deployAndReturnContractsForNftTests(deployer, testChain, accounts, isFastTrackEnabled));

await sendFunds('0.01', deployer.address, deployer)
await setupAccountWithMnemonic("dapptest", accounts.mnemonic, deployer);

// Deploy MockNFT
const erc721ContractArtifact = await hre.artifacts.readArtifact("MockERC721");
erc721token = await deployEthersContract("MockERC721", erc721ContractArtifact.abi, erc721ContractArtifact.bytecode, deployer, ["MockERC721", "MKTNFT"])

const numNftsToMint = 50
await estimateAndCall(erc721token, "batchMint", [deployer.address, numNftsToMint]);

// Deploy CW721 token with ERC721 pointer
const time = Date.now().toString();
const deployerSeiAddr = await getSeiAddress(deployer.address);
const cw721Details = await deployCw721WithPointer(deployerSeiAddr, deployer, time, evmRpcUrls[testChain])
erc721PointerToken = cw721Details.pointerContract;
cw721Address = cw721Details.cw721Address;
console.log("CW721 Address", cw721Address);
nftId1 = (await queryLatestNftIds(cw721Address, testChain)) + 1;
const numCwNftsToMint = 2;
for (let i = 1; i <= numCwNftsToMint; i++) {
await mintCw721(cw721Address, deployerSeiAddr, i)
}
const cwbal = await erc721PointerToken.balanceOf(deployer.address);
expect(cwbal).to.equal(numCwNftsToMint)

const nftMarketplaceArtifact = await hre.artifacts.readArtifact("NftMarketplace");
marketplace = await deployEthersContract("NftMarketplace", nftMarketplaceArtifact.abi, nftMarketplaceArtifact.bytecode, deployer)
for (let i = nftId1; i <= nftId1 + numCwNftsToMint; i++) {
await mintCw721(cw721Address, deployerSeiAddr, i);
console.log('nfts minted');
}
})

describe("Orders", function () {
async function testNFTMarketplaceOrder(buyer, seller, nftContract, nftId="", expectTransferFail=false) {
async function testNFTMarketplaceOrder(buyer, seller, nftContract, nftId = "", expectTransferFail = false) {
let tokenId;
// If nftId is manually supplied (for pointer contract), ensure that deployer owns that token.
if (nftId) {
Expand Down Expand Up @@ -117,7 +95,7 @@ describe("NFT Marketplace", function () {
const newSellerNftbalance = await nftContract.balanceOf(seller.address);
expect(Number(newSellerNftbalance)).to.be.lessThan(Number(sellerNftbalance), "NFT should have been transferred from the seller.")

nftOwner = await nftContract.ownerOf(tokenId);
let nftOwner = await nftContract.ownerOf(tokenId);
expect(nftOwner).to.equal(buyer.address, "NFT should have been transferred to the buyer.");
}

Expand Down Expand Up @@ -150,7 +128,7 @@ describe("NFT Marketplace", function () {
const buyer = buyerWallet.connect(hre.ethers.provider);
await sendFunds("0.5", buyer.address, deployer)
await sendFunds('0.01', buyer.address, buyer)
await testNFTMarketplaceOrder(buyer, deployer, erc721PointerToken, '1');
await testNFTMarketplaceOrder(buyer, deployer, erc721PointerToken, `${nftId1}`);
});

it("Currently does not allow listing or buying erc721 pointer by unassociated users", async function () {
Expand All @@ -164,13 +142,13 @@ describe("NFT Marketplace", function () {
const buyer = buyerWallet.connect(hre.ethers.provider);
await sendFunds("0.5", buyer.address, deployer)

await testNFTMarketplaceOrder(buyer, seller, erc721PointerToken, '2', true);
await testNFTMarketplaceOrder(buyer, seller, erc721PointerToken, `${nftId1 + 1}`, true);
});
})

after(async function () {
// Set the chain back to regular state
console.log("Resetting")
console.log("Resetting");
await execute(`seid config chain-id ${originalSeidConfig["chain-id"]}`)
await execute(`seid config node ${originalSeidConfig["node"]}`)
await execute(`seid config keyring-backend ${originalSeidConfig["keyring-backend"]}`)
Expand Down
Loading
Loading