Skip to content

Commit

Permalink
refactor tests to use chopsticks (#66)
Browse files Browse the repository at this point in the history
* use chopcticks to test relay

* updated tests for route xcm

* update

* add tests work

* clean up

* update
  • Loading branch information
shunjizhan authored Jul 8, 2024
1 parent d492a1b commit 9deceb7
Show file tree
Hide file tree
Showing 26 changed files with 978 additions and 1,359 deletions.
14 changes: 0 additions & 14 deletions .env.homa

This file was deleted.

8 changes: 4 additions & 4 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# relayer substrate addr: 5C82pcyrgW1gCm3jS8yBjo9AEp9HCUXiUkuKA1zWWiACgw1C

KARURA_ETH_RPC=https://eth-rpc-karura-testnet.aca-staging.network
KARURA_NODE_URL=wss://karura-testnet.aca-staging.network/rpc/karura/ws
KARURA_NODE_URL=wss://karura-testnet.aca-staging.network/rpc/ws
KARURA_PRIVATE_KEY=efb03e3f4fd8b3d7f9b14de6c6fb95044e2321d6bcb9dfe287ba987920254044

ACALA_ETH_RPC=https://eth-rpc-acala-testnet.aca-staging.network
ACALA_NODE_URL=wss://acala-dev.aca-dev.network/rpc/ws
ACALA_ETH_RPC=http://localhost:8545
ACALA_NODE_URL=ws://localhost:8000
ACALA_PRIVATE_KEY=efb03e3f4fd8b3d7f9b14de6c6fb95044e2321d6bcb9dfe287ba987920254044

PORT=3111
TESTNET_MODE=1
TESTNET_MODE=0
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ dist


**/.env
db.*
db.*

.env.prod
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,25 @@ POST /relay
=> TX receipt
{
to: '0xd11De1f930eA1F7Dd0290Fe3a2e35b9C91AEFb37',
from: '0xe3234f433914d4cfCF846491EC5a7831ab9f0bb3',
contractAddress: '0xd11De1f930eA1F7Dd0290Fe3a2e35b9C91AEFb37',
transactionIndex: 0,
gasUsed: { type: 'BigNumber', hex: '0x00' },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0x4fed14e47607e6088d1cb324ddc1bb14ea4c1f67507935b09cf093d11a9d3067',
transactionHash: '0x1878aed11208b91aa83573f4b88333ca6a0fe96657860470e9bc6002b39e9e28',
logs: [ [Object] ],
blockNumber: 95578,
confirmations: 1,
cumulativeGasUsed: { type: 'BigNumber', hex: '0x00' },
effectiveGasPrice: { type: 'BigNumber', hex: '0x01' },
status: 1,
type: 0,
byzantium: true,
events: [ [Object] ]
data: {
to: '0xd11De1f930eA1F7Dd0290Fe3a2e35b9C91AEFb37',
from: '0xe3234f433914d4cfCF846491EC5a7831ab9f0bb3',
contractAddress: '0xd11De1f930eA1F7Dd0290Fe3a2e35b9C91AEFb37',
transactionIndex: 0,
gasUsed: { type: 'BigNumber', hex: '0x00' },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0x4fed14e47607e6088d1cb324ddc1bb14ea4c1f67507935b09cf093d11a9d3067',
transactionHash: '0x1878aed11208b91aa83573f4b88333ca6a0fe96657860470e9bc6002b39e9e28',
logs: [ [Object] ],
blockNumber: 95578,
confirmations: 1,
cumulativeGasUsed: { type: 'BigNumber', hex: '0x00' },
effectiveGasPrice: { type: 'BigNumber', hex: '0x01' },
status: 1,
type: 0,
byzantium: true,
events: [ [Object] ]
}
}
```

Expand Down Expand Up @@ -594,7 +596,7 @@ yarn test:shouldRoute
yarn test:route
```

### test homa router setup
### test setup
first start a local acala fork
```
npx @acala-network/chopsticks@latest -c src/__tests__/configs/acala.yml -p 8000
Expand Down
3 changes: 2 additions & 1 deletion scripts/e2e-prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import path from 'path';
import { BSC_TOKEN, ETH_RPC , RELAYER_URL } from '../src/consts';
import { RouterChainId, getTokenBalance } from '../src/utils';
import { transferErc20, transferFromBSC } from './scriptUtils';
import { transferToken } from '../src/__tests__/testUtils';

dotenv.config({ path: path.join(__dirname, '.env') });
const key = process.env.KEY;
Expand Down Expand Up @@ -89,7 +90,7 @@ const routeWormhole = async (chainId: RouterChainId) => {
console.log(`token balance: ${bal}`);

console.log('xcming to router ...');
const txHash = await transferErc20(token, '0.05', routerAddr, wallet);
const txHash = await transferToken(routerAddr, wallet, token, 0.05);
console.log(`router received token: ${txHash}, waiting for routing ...`);

const routeRes = await axios.post(RELAYER_URL.ROUTE_WORMHOLE, { ...params });
Expand Down
56 changes: 0 additions & 56 deletions scripts/scriptUtils.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`/shouldRouteEuphrates > when should route 1`] = `
{
"data": {
"routerAddr": "0xCc968605e16C9dF27b03aE3E5273507216Fd4C9C",
"routerAddr": "0x6dd8372A9059254C19F4145556592eD01a5D8c06",
"shouldRoute": true,
},
}
Expand All @@ -12,7 +12,7 @@ exports[`/shouldRouteEuphrates > when should route 1`] = `
exports[`/shouldRouteEuphrates > when should route 2`] = `
{
"data": {
"routerAddr": "0xCc968605e16C9dF27b03aE3E5273507216Fd4C9C",
"routerAddr": "0x6dd8372A9059254C19F4145556592eD01a5D8c06",
"shouldRoute": true,
},
}
Expand All @@ -21,7 +21,7 @@ exports[`/shouldRouteEuphrates > when should route 2`] = `
exports[`/shouldRouteEuphrates > when should route 3`] = `
{
"data": {
"routerAddr": "0x84d5Beaa3808834c8A10e8DA241CDc0f1798E546",
"routerAddr": "0x844d07eCe43bF65bf36aa0398AeCE12641755FaA",
"shouldRoute": true,
},
}
Expand All @@ -30,7 +30,7 @@ exports[`/shouldRouteEuphrates > when should route 3`] = `
exports[`/shouldRouteEuphrates > when should route 4`] = `
{
"data": {
"routerAddr": "0x84d5Beaa3808834c8A10e8DA241CDc0f1798E546",
"routerAddr": "0x844d07eCe43bF65bf36aa0398AeCE12641755FaA",
"shouldRoute": true,
},
}
Expand All @@ -39,7 +39,7 @@ exports[`/shouldRouteEuphrates > when should route 4`] = `
exports[`/shouldRouteEuphrates > when should route 5`] = `
{
"data": {
"routerAddr": "0xAf808916d378Ee8EE0a737e2bf65Ad4dF1AcF342",
"routerAddr": "0xCaC1D0397669E71B25410171CE6f77Af750e1B2d",
"shouldRoute": true,
},
}
Expand All @@ -48,7 +48,7 @@ exports[`/shouldRouteEuphrates > when should route 5`] = `
exports[`/shouldRouteEuphrates > when should route 6`] = `
{
"data": {
"routerAddr": "0xAf808916d378Ee8EE0a737e2bf65Ad4dF1AcF342",
"routerAddr": "0xCaC1D0397669E71B25410171CE6f77Af750e1B2d",
"shouldRoute": true,
},
}
Expand All @@ -57,7 +57,7 @@ exports[`/shouldRouteEuphrates > when should route 6`] = `
exports[`/shouldRouteEuphrates > when should route 7`] = `
{
"data": {
"routerAddr": "0x804Beb16fcd17D3AC84de0614fC9D9e0550BEBf7",
"routerAddr": "0x274d69D18Ec8d3b9d3E6732013DeB57E4Cf89Be8",
"shouldRoute": true,
},
}
Expand All @@ -66,7 +66,25 @@ exports[`/shouldRouteEuphrates > when should route 7`] = `
exports[`/shouldRouteEuphrates > when should route 8`] = `
{
"data": {
"routerAddr": "0x804Beb16fcd17D3AC84de0614fC9D9e0550BEBf7",
"routerAddr": "0x274d69D18Ec8d3b9d3E6732013DeB57E4Cf89Be8",
"shouldRoute": true,
},
}
`;

exports[`/shouldRouteEuphrates > when should route 9`] = `
{
"data": {
"routerAddr": "0x825E69D8f27010d8e5D4e96913A8571221373789",
"shouldRoute": true,
},
}
`;

exports[`/shouldRouteEuphrates > when should route 10`] = `
{
"data": {
"routerAddr": "0x825E69D8f27010d8e5D4e96913A8571221373789",
"shouldRoute": true,
},
}
Expand Down
99 changes: 99 additions & 0 deletions src/__tests__/__snapshots__/relay.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`/shouldRelay > when should relay 1`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 2`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 3`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 4`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 5`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 6`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 7`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 8`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 9`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 10`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 11`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 12`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 13`] = `
{
"msg": "",
"shouldRelay": true,
}
`;

exports[`/shouldRelay > when should relay 14`] = `
{
"msg": "",
"shouldRelay": true,
}
`;
Loading

0 comments on commit 9deceb7

Please sign in to comment.