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

Add NFT Marketplace Tests #1829

Merged
merged 62 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
99b60ab
test
mj850 Aug 13, 2024
5b9d7b4
test
mj850 Aug 13, 2024
6439cbd
add more setup
mj850 Aug 13, 2024
aed4dec
add to path
mj850 Aug 13, 2024
18b9334
githubpath
mj850 Aug 13, 2024
020cda0
seid path
mj850 Aug 13, 2024
7f381c1
dapp tests
mj850 Aug 13, 2024
fd231da
try artifacts
mj850 Aug 13, 2024
36c5296
ditch setup step
mj850 Aug 13, 2024
6579e77
deps
mj850 Aug 13, 2024
b47af79
test workflow
mj850 Aug 14, 2024
d640e56
set keyring
mj850 Aug 14, 2024
d06ac8c
without
mj850 Aug 14, 2024
90d0f1b
keys add
mj850 Aug 14, 2024
42d9ac8
add to sh
mj850 Aug 15, 2024
4798878
nobackend
mj850 Aug 15, 2024
f17b914
no script
mj850 Aug 15, 2024
447df6e
test
mj850 Aug 15, 2024
2057cc8
keyring
mj850 Aug 15, 2024
16246e7
no sh
mj850 Aug 15, 2024
9a1b7b2
test
mj850 Aug 15, 2024
4f30529
fix flakiness
mj850 Aug 15, 2024
2619288
cleanup
mj850 Aug 15, 2024
903ebe1
move seid config command
mj850 Aug 15, 2024
fe89104
only if docker
mj850 Aug 15, 2024
aa80069
test without
mj850 Aug 15, 2024
29c36f6
if isdocker
mj850 Aug 15, 2024
96a1d9f
printf mnemonic
mj850 Aug 15, 2024
f4c89b7
try escape path
mj850 Aug 15, 2024
1614f30
try single quotes
mj850 Aug 15, 2024
aa8160c
try modifying execute
mj850 Aug 15, 2024
8f02f10
no path
mj850 Aug 15, 2024
7bdeda0
backend
mj850 Aug 15, 2024
3ab4fc7
try without keyring
mj850 Aug 15, 2024
fd65314
move keyring
mj850 Aug 15, 2024
2954d1f
path
mj850 Aug 15, 2024
6249603
basedir
mj850 Aug 15, 2024
80e6db9
try pwd
mj850 Aug 15, 2024
34f2fb2
config reset
mj850 Aug 15, 2024
8f988ef
seid config
mj850 Aug 15, 2024
6613f65
redeclare
mj850 Aug 15, 2024
298f6ad
print
mj850 Aug 15, 2024
a16ebb9
docker path
mj850 Aug 15, 2024
efcd4d5
dynamic path
mj850 Aug 15, 2024
2fa74b0
config for all
mj850 Aug 15, 2024
8fc95f6
full
mj850 Aug 15, 2024
1c17fe1
lint issue
mj850 Aug 15, 2024
501be8e
backend
mj850 Aug 15, 2024
43609a0
cleanup
mj850 Aug 16, 2024
98fb6e5
seaport starter
mj850 Aug 16, 2024
e440e31
merge confi
mj850 Aug 16, 2024
c957914
working locally
mj850 Aug 22, 2024
1f1a839
working on all chains
mj850 Aug 22, 2024
0323846
add readme
mj850 Aug 22, 2024
daa5e71
Merge branch 'main' into mj/seaportTest
mj850 Aug 22, 2024
0da43ff
keyring
mj850 Aug 22, 2024
ab4b96a
stray argument in unit test
mj850 Aug 22, 2024
feb3269
cleanup
mj850 Aug 22, 2024
8ddba85
reduce costs
mj850 Aug 22, 2024
1567e02
scripts
mj850 Aug 24, 2024
c07ccdb
Merge branch 'main' into mj/seaportTest
mj850 Aug 24, 2024
c912ea9
Merge branch 'main' into mj/seaportTest
mj850 Sep 4, 2024
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
Prev Previous commit
Next Next commit
test workflow
  • Loading branch information
mj850 committed Aug 14, 2024
commit b47af79f3554bc4ef7013713999f8d9a58ce77f8
4 changes: 4 additions & 0 deletions .github/workflows/dapp_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
runs-on: ubuntu-latest
environment:
name: devnet
env:
DAPP_TESTS_MNEMONIC: ${{ secrets.DAPP_TESTS_MNEMONIC }}
steps:
- uses: actions/checkout@v3

Expand All @@ -35,6 +37,8 @@ jobs:
runs-on: ubuntu-latest
environment:
name: testnet
env:
DAPP_TESTS_MNEMONIC: ${{ secrets.DAPP_TESTS_MNEMONIC }}
steps:
- uses: actions/checkout@v3

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DAPP_TESTS_MNEMONIC: ${{ secrets.DAPP_TESTS_MNEMONIC }}
strategy:
# other jobs should run even if one integration test fails
fail-fast: false
Expand Down
35 changes: 21 additions & 14 deletions contracts/test/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ async function bankSend(toAddr, fromKey, amount="100000000000", denom="usei") {
return result
}

async function fundSeiAddress(seiAddr, amount="100000000000", denom="usei") {
return await execute(`seid tx bank send ${adminKeyName} ${seiAddr} ${amount}${denom} -b block --fees 20000usei -y`);
async function fundSeiAddress(seiAddr, amount="100000000000", denom="usei", funder=adminKeyName) {
return await execute(`seid tx bank send ${funder} ${seiAddr} ${amount}${denom} -b block --fees 20000usei -y`);
}

async function getSeiBalance(seiAddr, denom="usei") {
Expand Down Expand Up @@ -182,7 +182,7 @@ async function createTokenFactoryTokenAndMint(name, amount, recipient, from=admi
const mint_command = `seid tx tokenfactory mint ${amount}${token_denom} --from ${from} --gas=5000000 --fees=1000000usei -y --broadcast-mode block -o json`
await execute(mint_command);

const send_command = `seid tx bank send ${adminKeyName} ${recipient} ${amount}${token_denom} --from ${from} --gas=5000000 --fees=1000000usei -y --broadcast-mode block -o json`
const send_command = `seid tx bank send ${from} ${recipient} ${amount}${token_denom} --from ${from} --gas=5000000 --fees=1000000usei -y --broadcast-mode block -o json`
await execute(send_command);
return token_denom
}
Expand All @@ -193,12 +193,13 @@ async function getPointerForNative(name) {
return JSON.parse(output);
}

async function storeWasm(path) {
const command = `seid tx wasm store ${path} --from ${adminKeyName} --gas=5000000 --fees=1000000usei -y --broadcast-mode block -o json`
async function storeWasm(path, from=adminKeyName) {
const command = `seid tx wasm store ${path} --from ${from} --gas=5000000 --fees=1000000usei -y --broadcast-mode block -o json`
const output = await execute(command);
const response = JSON.parse(output)
return getEventAttribute(response, "store_code", "code_id")
}

async function getPointerForCw20(cw20Address) {
const command = `seid query evm pointer CW20 ${cw20Address} -o json`
const output = await execute(command);
Expand All @@ -211,8 +212,11 @@ async function getPointerForCw721(cw721Address) {
return JSON.parse(output);
}

async function deployErc20PointerForCw20(provider, cw20Address, attempts=10) {
const command = `seid tx evm register-evm-pointer CW20 ${cw20Address} --from=admin -b block`
async function deployErc20PointerForCw20(provider, cw20Address, attempts=10, from=adminKeyName, evmRpc="") {
let command = `seid tx evm register-evm-pointer CW20 ${cw20Address} --from=${from} -b block`
if (evmRpc) {
command = command + ` --evm-rpc=${evmRpc}`
}
const output = await execute(command);
const txHash = output.replace(/.*0x/, "0x").trim()
let attempt = 0;
Expand All @@ -229,8 +233,11 @@ async function deployErc20PointerForCw20(provider, cw20Address, attempts=10) {
throw new Error("contract deployment failed")
}

async function deployErc20PointerNative(provider, name) {
const command = `seid tx evm call-precompile pointer addNativePointer ${name} --from=admin -b block`
async function deployErc20PointerNative(provider, name, from=adminKeyName, evmRpc="") {
let command = `seid tx evm call-precompile pointer addNativePointer ${name} --from=${from} -b block`
if (evmRpc) {
command = command + ` --evm-rpc=${evmRpc}`
}
const output = await execute(command);
const txHash = output.replace(/.*0x/, "0x").trim()
let attempt = 0;
Expand Down Expand Up @@ -263,14 +270,14 @@ async function deployErc721PointerForCw721(provider, cw721Address) {
throw new Error("contract deployment failed")
}

async function deployWasm(path, adminAddr, label, args = {}) {
const codeId = await storeWasm(path)
return await instantiateWasm(codeId, adminAddr, label, args)
async function deployWasm(path, adminAddr, label, args = {}, from=adminKeyName) {
const codeId = await storeWasm(path, from)
return await instantiateWasm(codeId, adminAddr, label, args, from)
}

async function instantiateWasm(codeId, adminAddr, label, args = {}) {
async function instantiateWasm(codeId, adminAddr, label, args = {}, from=adminKeyName) {
const jsonString = JSON.stringify(args).replace(/"/g, '\\"');
const command = `seid tx wasm instantiate ${codeId} "${jsonString}" --label ${label} --admin ${adminAddr} --from ${adminKeyName} --gas=5000000 --fees=1000000usei -y --broadcast-mode block -o json`;
const command = `seid tx wasm instantiate ${codeId} "${jsonString}" --label ${label} --admin ${adminAddr} --from ${from} --gas=5000000 --fees=1000000usei -y --broadcast-mode block -o json`;
const output = await execute(command);
const response = JSON.parse(output);
return getEventAttribute(response, "instantiate", "_contract_address");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const rpcUrls = {
"devnet": "https://rpc-arctic-1.sei-apis.com"
}

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

const chainIds = {
"testnet": "atlantic-2",
"devnet": "arctic-1"
Expand All @@ -22,5 +27,6 @@ module.exports = {
tokenFactoryDenoms,
cw20Addresses,
rpcUrls,
evmRpcUrls,
chainIds
}
25 changes: 21 additions & 4 deletions integration_test/dapp_tests/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,30 @@ module.exports = {
networks: {
seilocal: {
url: "http://127.0.0.1:8545",
address: ["0xF87A299e6bC7bEba58dbBe5a5Aa21d49bCD16D52", "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"],
accounts: ["0x57acb95d82739866a5c29e40b0aa2590742ae50425b7dd5b5d279a986370189e", "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"],
accounts: {
mnemonic: process.env.DAPP_TESTS_MNEMONIC,
path: "m/44'/60'/0'/0/0",
initialIndex: 0,
count: 1
},
},
testnet: {
url: "https://evm-rpc-testnet.sei-apis.com",
address: ["0xF87A299e6bC7bEba58dbBe5a5Aa21d49bCD16D52", "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"],
accounts: ["0x57acb95d82739866a5c29e40b0aa2590742ae50425b7dd5b5d279a986370189e", "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"],
accounts: {
mnemonic: process.env.DAPP_TESTS_MNEMONIC,
path: "m/44'/60'/0'/0/0",
initialIndex: 0,
count: 1
},
},
devnet: {
url: "https://evm-rpc-arctic-1.sei-apis.com",
accounts: {
mnemonic: process.env.DAPP_TESTS_MNEMONIC,
path: "m/44'/60'/0'/0/0",
initialIndex: 0,
count: 1
},
},
},
};
57 changes: 47 additions & 10 deletions integration_test/dapp_tests/steak/SteakTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const {
getEvmAddress,
fundSeiAddress,
associateKey,
execute,
getSeiAddress
} = require("../../../contracts/test/lib.js");
const {
getValidators,
Expand All @@ -14,38 +16,47 @@ const {
queryTokenBalance,
unbond,
transferTokens,
setupAccountWithMnemonic,
} = require("./utils.js");

const { expect } = require("chai");
const { v4: uuidv4 } = require("uuid");
const hre = require("hardhat");
const {chainIds, rpcUrls, evmRpcUrls} = require("../constants");
const {sendFunds} = require("../uniswap/uniswapHelpers");

const STEAK_HUB_WASM =
"../integration_test/dapp_tests/steak/contracts/steak_hub.wasm";
"../dapp_tests/steak/contracts/steak_hub.wasm";
const STEAK_TOKEN_WASM =
"../integration_test/dapp_tests/steak/contracts/steak_token.wasm";
"../dapp_tests/steak/contracts/steak_token.wasm";

const testChain = process.env.DAPP_TEST_ENV;


describe("Steak", async function () {
let owner;
let hubAddress;
let tokenAddress;
let tokenPointer;

async function setupAccount(baseName, associate = true) {
async function setupAccount(baseName, associate = true, amount="100000000000", denom="usei", funder='admin') {
const uniqueName = `${baseName}-${uuidv4()}`;

const account = await addAccount(uniqueName);
await fundSeiAddress(account.address);
await fundSeiAddress(account.address, amount, denom, funder);
if (associate) {
await associateKey(account.address);
}

return account;
}

async function deployContracts(ownerAddress) {
// Store CW20 token wasm
const tokenCodeId = await storeWasm(STEAK_TOKEN_WASM);
const tokenCodeId = await storeWasm(STEAK_TOKEN_WASM, ownerAddress);

// Store Hub contract
const hubCodeId = await storeWasm(STEAK_HUB_WASM);
const hubCodeId = await storeWasm(STEAK_HUB_WASM, ownerAddress);

// Instantiate hub and token contracts
const validators = await getValidators();
Expand All @@ -69,8 +80,12 @@ describe("Steak", async function () {
// Deploy pointer for token contract
const pointerAddr = await deployErc20PointerForCw20(
hre.ethers.provider,
contractAddresses.tokenContract
contractAddresses.tokenContract,
10,
ownerAddress,
evmRpcUrls[testChain]
);

const tokenPointer = new hre.ethers.Contract(
pointerAddr,
ABI.ERC20,
Expand Down Expand Up @@ -105,7 +120,20 @@ describe("Steak", async function () {

before(async function () {
// Set up the owner account
owner = await setupAccount("steak-owner");
if (testChain === 'seilocal') {
owner = await setupAccount("steak-owner");
} 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]}`)

const accounts = hre.config.networks[testChain].accounts
const deployerWallet = hre.ethers.Wallet.fromMnemonic(accounts.mnemonic, accounts.path);
const deployer = deployerWallet.connect(hre.ethers.provider)
console.log(deployer.address)
await sendFunds('0.01', deployer.address, deployer)
owner = await setupAccountWithMnemonic("steak-owner", accounts.mnemonic, accounts.path, deployer)
}

// Store and deploy contracts
({ hubAddress, tokenAddress, tokenPointer } = await deployContracts(
Expand All @@ -130,7 +158,7 @@ describe("Steak", async function () {
});

it("Unassociated account should be able to bond", async function () {
const unassociatedAccount = await setupAccount("unassociated", false);
const unassociatedAccount = await setupAccount("unassociated", false, '2000000', 'usei', owner.address);
// Verify that account is not associated yet
const initialEvmAddress = await getEvmAddress(
unassociatedAccount.address
Expand All @@ -144,7 +172,7 @@ describe("Steak", async function () {
expect(evmAddress).to.not.be.empty;

// Send tokens to a new unassociated account
const newUnassociatedAccount = await setupAccount("unassociated", false);
const newUnassociatedAccount = await setupAccount("unassociated", false, '2000000', 'usei', owner.address);
const transferAmount = 500000;
await transferTokens(
tokenAddress,
Expand All @@ -162,4 +190,13 @@ describe("Steak", async function () {
await testUnbonding(newUnassociatedAccount.address, transferAmount / 2);
});
});

after(async function () {
// Set the chain back to regular state
console.log("Resetting")
if (testChain !== 'seilocal') {
await execute(`seid config chain-id sei-chain`)
await execute(`seid config node tcp://localhost:26657`)
}
})
});
38 changes: 36 additions & 2 deletions integration_test/dapp_tests/steak/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { execute } = require("../../../contracts/test/lib");
const { execute, getSeiAddress } = require("../../../contracts/test/lib");
const {v4: uuidv4} = require("uuid");

const encodeBase64 = (obj) => {
return Buffer.from(JSON.stringify(obj)).toString("base64");
Expand Down Expand Up @@ -27,7 +28,7 @@ const instantiateHubContract = async (
label
) => {
const jsonString = JSON.stringify(instantiateMsg).replace(/"/g, '\\"');
const command = `seid tx wasm instantiate ${codeId} "${jsonString}" --label ${label} --admin ${adminAddress} --from admin --gas=5000000 --fees=1000000usei -y --broadcast-mode block -o json`;
const command = `seid tx wasm instantiate ${codeId} "${jsonString}" --label ${label} --admin ${adminAddress} --from ${adminAddress} --gas=5000000 --fees=1000000usei -y --broadcast-mode block -o json`;
const output = await execute(command);
const response = JSON.parse(output);
// Get all attributes with _contractAddress
Expand Down Expand Up @@ -142,6 +143,37 @@ const transferTokens = async (tokenAddress, sender, destination, amount) => {
return response;
};

async function setupAccountWithMnemonic(baseName, mnemonic, path, deployer) {
const uniqueName = `${baseName}-${uuidv4()}`;
const address = await getSeiAddress(deployer.address)

return await addDeployerAccount(uniqueName, address, mnemonic, path)
}

async function addDeployerAccount(keyName, address, mnemonic, path) {
// First try to retrieve by address
try {
const output = await execute(`seid keys show ${address} --output json`);
return JSON.parse(output);
} catch (e) {
console.log(e)
}

// Since the address doesn't exist, create the key with random name
try {
const output = await execute(`printf "${mnemonic}" | seid keys add ${keyName}-${Date.now()} --recover --hd-path "${path}"`)
if (output.code !== 0) {
throw new Error(output.raw_log);
}
}
catch (e) {
console.log("Key doesn't exist", e);
}

const output = await execute(`seid keys show ${keyName} --output json`);
return JSON.parse(output);
}

module.exports = {
getValidators,
instantiateHubContract,
Expand All @@ -150,5 +182,7 @@ module.exports = {
harvest,
queryTokenBalance,
addAccount,
addDeployerAccount,
setupAccountWithMnemonic,
transferTokens,
};
Loading
Loading