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 6 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
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?

"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"
}
15 changes: 12 additions & 3 deletions integration_test/dapp_tests/constants.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
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",
"devnetFastTrack": "https://rpc-arctic-1.sei-apis.com",
Copy link
Contributor

Choose a reason for hiding this comment

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

can devnetFastTrack just use the same rpc as devnet?

"seiClusterFastTrack": ""
}

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",
"devnetFastTrack": "https://evm-rpc-arctic-1.sei-apis.com",
"seiClusterFastTrack": ""
}

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

module.exports = {
Expand Down
18 changes: 18 additions & 0 deletions integration_test/dapp_tests/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ module.exports = {
count: 1
},
},
seiClusterFastTrack: {
url: "http://127.0.0.1:8545",
accounts: {
mnemonic: process.env.DAPP_TESTS_MNEMONIC,
path: "m/44'/118'/0'/0/0",
initialIndex: 0,
count: 1
},
},
testnet: {
url: "https://evm-rpc-testnet.sei-apis.com",
accounts: {
Expand All @@ -43,5 +52,14 @@ module.exports = {
count: 1
},
},
devnetFastTrack: {
Copy link
Contributor

Choose a reason for hiding this comment

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

how is this config different than devnet?

url: "https://evm-rpc-arctic-1.sei-apis.com",
accounts: {
mnemonic: process.env.DAPP_TESTS_MNEMONIC,
path: "m/44'/118'/0'/0/0",
initialIndex: 0,
count: 1
},
},
},
};
77 changes: 25 additions & 52 deletions integration_test/dapp_tests/nftMarketplace/nftMarketplaceTests.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,39 @@
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 } = require("../../../contracts/test/lib.js");

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

let marketplace, deployer, erc721token, erc721PointerToken, cw721Address, originalSeidConfig;
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);

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`)

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();
originalSeidConfig = setDaemonConfig(testChain);
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);
({
marketplace,
erc721token,
cw721Address,
erc721PointerToken
} = await deployAndReturnContractsForNftTests(deployer, testChain, accounts));
nftId1 = (await queryLatestNftIds(cw721Address)) + 1;
const numCwNftsToMint = 2;
for (let i = 1; i <= numCwNftsToMint; i++) {
await mintCw721(cw721Address, deployerSeiAddr, i)
for (let i = nftId1; i <= nftId1 + numCwNftsToMint; i++) {
await mintCw721(cw721Address, deployerSeiAddr, i);
console.log('nfts minted');
}
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)
})

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 +90,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 +123,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,15 +137,15 @@ 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")
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"]}`)
// Set the chain back to regular state
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"]}`)
})
})
Loading
Loading