Skip to content

Commit

Permalink
updated e2e tests infra
Browse files Browse the repository at this point in the history
  • Loading branch information
shunjizhan committed Dec 15, 2023
1 parent 8e8d891 commit abaa915
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 13 deletions.
20 changes: 19 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"cwd": "${workspaceRoot}/packages/eth-rpc-adapter",
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**"]
}
},
{
"name": "hardhat test",
"type": "node",
Expand All @@ -38,6 +38,24 @@
"cwd": "${workspaceRoot}/scripts/runtime-upgrade-tests",
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**"]
},
{
"type": "node",
"request": "launch",
"name": "vitest",
"autoAttachChildProcesses": true,
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**"
],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": [
"packages/eth-rpc-adapter/src/__tests__/e2e",
"--config",
"packages/eth-rpc-adapter/vitest.config.e2e.ts"
],
"smartStep": true,
"console": "integratedTerminal"
}
]
}
12 changes: 6 additions & 6 deletions scripts/e2e-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ yarn build
```

## For Runtime Upgrade
- start a karura/acala fork
- get current latest blocknumber and put it in `subql/{karura,acala}/config.yaml
```
npx @acala-network/chopsticks@latest -c configs/karura.yml
npx @acala-network/chopsticks@latest -c configs/acala.yml
./scripts/block-number.sh
```

- start a eth rpc adapter
- start a full normal-sealing bodhi stack with local karura/acala fork
```
npx @acala-network/eth-rpc-adapter@latest -e ws://localhost:8000
docker compose -f ./docker-compose-karura.yml up
docker compose -f ./docker-compose-acala.yml up
```

- run tests
Expand All @@ -27,7 +27,7 @@ yarn test:acala
## For Local Mandala Tests
- start a full normal-sealing local mandala stack with subql (node can't be instant sealing if working with subway)
```
docker compose
docker compose -f ./docker-compose-subway.yml up
```

- run tests
Expand Down
28 changes: 28 additions & 0 deletions scripts/e2e-tests/configs/subql/acala.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
specVersion: 1.0.0
name: '@acala-network/evm-subql'
version: 1.0.0
runner:
node:
name: '@subql/node'
version: 1.21.2
query:
name: '@subql/query'
version: 1.4.0
description: 'subquery for Acala EVM+'
repository: 'https://github.com/AcalaNetwork/bodhi.js/tree/master/evm-subql'
schema:
file: ./schema.graphql
network:
# Acala
chainId: '0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c'
endpoint: ws://chopsticks:8000
chaintypes:
file: ./dist/chain-types/index.js
dataSources:
- kind: substrate/Runtime
startBlock: 5108461
mapping:
file: ./dist/index.js
handlers:
- handler: handleBlock
kind: substrate/BlockHandler
28 changes: 28 additions & 0 deletions scripts/e2e-tests/configs/subql/karura.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
specVersion: 1.0.0
name: '@acala-network/evm-subql'
version: 1.0.0
runner:
node:
name: '@subql/node'
version: 1.21.2
query:
name: '@subql/query'
version: 1.4.0
description: 'subquery for Karura EVM+'
repository: 'https://github.com/AcalaNetwork/bodhi.js/tree/master/evm-subql'
schema:
file: ./schema.graphql
network:
# Karura
chainId: '0xbaf5aabe40646d11f0ee8abbdc64f4a4b7674925cba08e4a05ff9ebed6e2126b'
endpoint: ws://chopsticks:8000
chaintypes:
file: ./dist/chain-types/index.js
dataSources:
- kind: substrate/Runtime
startBlock: 5853808
mapping:
file: ./dist/index.js
handlers:
- handler: handleBlock
kind: substrate/BlockHandler
83 changes: 83 additions & 0 deletions scripts/e2e-tests/docker-compose-acala.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
version: '3'

services:
chopsticks:
image: oven/bun
container_name: chopsticks-node
volumes:
- ./:/home/bun/app
- ./.bunx-cache:/root/.bun/install/cache
command: bunx @acala-network/chopsticks@latest -c ./configs/acala.yml
ports:
- 8000:8000

postgres:
image: postgres:12-alpine
container_name: postgres
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: postgres

subquery-node:
image: acala/evm-subql:2.7.16
volumes:
- ./configs/subql/karura.yaml:/app/karura.yaml
- ./configs/subql/acala.yaml:/app/acala.yaml
ports:
- 3000:3000
depends_on:
- chopsticks
- postgres
restart: always
extra_hosts:
- host.docker.internal:host-gateway
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: host.docker.internal
DB_PORT: 5432
command:
- -f=./acala.yaml
- --network-endpoint=ws://chopsticks:8000
- --db-schema=acala_evm
- --log-level=debug
- --unsafe
- --disable-historical

graphql-engine:
image: onfinality/subql-query:v1.4.0
container_name: graphql-engine
ports:
- 3001:3001
depends_on:
- subquery-node
restart: always
extra_hosts:
- host.docker.internal:host-gateway
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: host.docker.internal
DB_PORT: 5432
PORT: 3001
command:
- --name=acala_evm
- --playground
- --indexer=http://subquery-node:3000

eth-rpc-adapter:
image: acala/eth-rpc-adapter:2.7.16
environment:
- SUBQL_URL=http://graphql-engine:3001
- ENDPOINT_URL=ws://chopsticks:8000
command: yarn start
ports:
- 8545:8545
restart: always
depends_on:
- chopsticks
extra_hosts:
- host.docker.internal:host-gateway
83 changes: 83 additions & 0 deletions scripts/e2e-tests/docker-compose-karura.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
version: '3'

services:
chopsticks:
image: oven/bun
container_name: chopsticks-node
volumes:
- ./:/home/bun/app
- ./.bunx-cache:/root/.bun/install/cache
command: bunx @acala-network/chopsticks@latest -c ./configs/karura.yml
ports:
- 8000:8000

postgres:
image: postgres:12-alpine
container_name: postgres
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: postgres

subquery-node:
image: acala/evm-subql:2.7.16
volumes:
- ./configs/subql/karura.yaml:/app/karura.yaml
- ./configs/subql/acala.yaml:/app/acala.yaml
ports:
- 3000:3000
depends_on:
- chopsticks
- postgres
restart: always
extra_hosts:
- host.docker.internal:host-gateway
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: host.docker.internal
DB_PORT: 5432
command:
- -f=./karura.yaml
- --network-endpoint=ws://chopsticks:8000
- --db-schema=acala_evm
- --log-level=debug
- --unsafe
- --disable-historical

graphql-engine:
image: onfinality/subql-query:v1.4.0
container_name: graphql-engine
ports:
- 3001:3001
depends_on:
- subquery-node
restart: always
extra_hosts:
- host.docker.internal:host-gateway
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: host.docker.internal
DB_PORT: 5432
PORT: 3001
command:
- --name=acala_evm
- --playground
- --indexer=http://subquery-node:3000

eth-rpc-adapter:
image: acala/eth-rpc-adapter:2.7.16
environment:
- SUBQL_URL=http://graphql-engine:3001
- ENDPOINT_URL=ws://chopsticks:8000
command: yarn start
ports:
- 8545:8545
restart: always
depends_on:
- chopsticks
extra_hosts:
- host.docker.internal:host-gateway
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ services:
DB_HOST: host.docker.internal
DB_PORT: 5432
command:
- -f=project.yaml # local mandala
- -f=./project.yaml
- --network-endpoint=ws://mandala-node:9944
- --db-schema=acala_evm
- --log-level=debug
Expand Down Expand Up @@ -76,12 +76,12 @@ services:
- mandala-node
- graphql-engine
ports:
- 8546:8546
- 8545:8545
extra_hosts:
- host.docker.internal:host-gateway
environment:
# - LOCAL_MODE=1
- SUBQL_URL=http://graphql-engine:3001
- ENDPOINT_URL=ws://mandala-node:9944
- PORT=8546
# - PORT=8546
command: yarn start
24 changes: 24 additions & 0 deletions scripts/e2e-tests/scripts/block-number.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Function to get block number from a given JSON RPC URL
getBlockNumber() {
local rpcUrl=$1
local networkName=$2

response=$(curl -s -H "Content-Type: application/json" --data \
'{"jsonrpc":"2.0", "method":"chain_getHeader", "params":[], "id":1}' \
$rpcUrl)

# Extract the block number in hexadecimal, removing the "0x" prefix
blockNumberHex=$(echo $response | jq -r '.result.number' | sed 's/0x//')

# Convert the hexadecimal block number to decimal
blockNumberDecimal=$((16#$blockNumberHex))

# Print the block number
echo "$networkName Block Number: $blockNumberDecimal"
}

# Call the function with Karura and Acala URLs
getBlockNumber "https://karura-rpc.aca-api.network" "karura"
getBlockNumber "https://acala-rpc.aca-api.network" "acala"
3 changes: 2 additions & 1 deletion scripts/e2e-tests/test/operations.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { expect } from 'chai';
import { ethers, network } from 'hardhat';
import { ERC20__factory, type Token } from '../typechain-types';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { parseEther, parseUnits } from 'ethers/lib/utils';

import { ERC20__factory, type Token } from '../typechain-types';

const one = parseEther('1');

describe('evm operations', function () {
Expand Down
8 changes: 6 additions & 2 deletions scripts/e2e-tests/test/subscription.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ import { ethers, network } from 'hardhat';
import { before, after } from 'mocha';
import { parseUnits } from 'ethers/lib/utils';
import { AcalaJsonRpcProvider, sleep } from '@acala-network/eth-providers';
import { ACA } from '@acala-network/contracts/utils/AcalaAddress';
import { KAR } from '@acala-network/contracts/utils/KaruraAddress';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { JsonRpcProvider } from '@ethersproject/providers';
import { Wallet } from 'ethers';

import { ERC20, ERC20__factory } from '../typechain-types';
import { SubsManager, getAddrSelector } from './utils';

const TOKEN_ADDR = network.name === 'acala'
? ACA
: KAR;
const oneAcaErc20 = parseUnits('1', 12);
const ACA_ADDR = '0x0000000000000000000100000000000000000000';
const TRANSFER_SELECTOR = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';

const ETH_RPC_URL = network.config.url;
Expand All @@ -33,7 +37,7 @@ describe('eth subscription', () => {
console.log('setting up subscription ...');

[deployer, user] = await ethers.getSigners();
aca = ERC20__factory.connect(ACA_ADDR, deployer);
aca = ERC20__factory.connect(TOKEN_ADDR, deployer);

provider = new AcalaJsonRpcProvider(ETH_RPC_URL);
sm = new SubsManager(ETH_RPC_URL_WS);
Expand Down
Binary file modified scripts/e2e-tests/wasm/karura-2230.wasm
Binary file not shown.

0 comments on commit abaa915

Please sign in to comment.