Skip to content

Commit b2028fe

Browse files
authored
Enable test-ts (#2933)
* enable test-ts * fix * fix
1 parent da1a238 commit b2028fe

File tree

10 files changed

+1236
-1118
lines changed

10 files changed

+1236
-1118
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,4 @@ jobs:
138138
- name: Run ts tests
139139
run: |
140140
npm install -g yarn
141-
# TODO: update bodhi & enable this
142-
# make test-ts
141+
make test-ts

ts-tests/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
"build": "waffle waffle.json"
99
},
1010
"dependencies": {
11-
"@acala-network/api": "6.1.3",
12-
"@acala-network/bodhi": "~2.8.9",
13-
"@acala-network/chopsticks": "^0.13.3",
11+
"@acala-network/api": "6.3.0",
12+
"@acala-network/bodhi": "~2.10.0",
13+
"@acala-network/chopsticks": "^1.2.3",
1414
"@openzeppelin/contracts": "5.0.2",
15-
"@polkadot/api": "12.4.1",
15+
"@polkadot/api": "16.4.8",
1616
"ethereum-waffle": "4.0.10",
1717
"ethers": "5.7.2",
18-
"vitest": "^2.0.5"
18+
"vitest": "^3.2.4"
1919
},
2020
"packageManager": "yarn@4.4.0"
2121
}

ts-tests/tests/setup.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
process.on('unhandledRejection', (reason: any) => {
2+
const message = reason?.message || String(reason);
3+
4+
if (
5+
message.includes('Normal Closure') ||
6+
message.includes('disconnected from ws://')
7+
) {
8+
return;
9+
}
10+
11+
console.error('Unhandled Rejection:', reason);
12+
throw reason;
13+
});
14+
15+
process.on('uncaughtException', (error: Error) => {
16+
if (
17+
error.message.includes('Normal Closure') ||
18+
error.message.includes('disconnected from ws://')
19+
) {
20+
return;
21+
}
22+
console.error('Uncaught Exception:', error);
23+
throw error;
24+
});

ts-tests/tests/test-balance.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ describeWithAcala("Acala RPC (Balance)", (context) => {
1111
});
1212

1313
it("genesis balance is setup correctly", async function () {
14-
expect((await context.provider.getBalance(alice.getAddress())).toString()).to.equal("8999999995648303331000000");
15-
expect((await context.provider.getBalance(alice.getAddress(), "latest")).toString()).to.equal("8999999995648303331000000");
14+
expect((await context.provider.getBalance(alice.getAddress())).toString()).to.equal("8999999995072568421000000");
15+
expect((await context.provider.getBalance(alice.getAddress(), "latest")).toString()).to.equal("8999999995072568421000000");
1616

1717
expect((await context.provider.getBalance(alice.getAddress(), "latest")).toString())
1818
.to.equal((await context.provider.api.query.system.account(alice.substrateAddress)).data.free.toString() + "000000");
1919
});
2020

2121
it("balance to be updated after transfer", async function () {
22-
expect((await context.provider.getBalance(alice.getAddress())).toString()).to.equal("8999999995648303331000000");
23-
expect((await context.provider.getBalance(alice_stash.getAddress())).toString()).to.equal("10100000995648309012000000");
22+
expect((await context.provider.getBalance(alice.getAddress())).toString()).to.equal("8999999995072568421000000");
23+
expect((await context.provider.getBalance(alice_stash.getAddress())).toString()).to.equal("10100000995072575531000000");
2424

2525
await transfer(context, alice.substrateAddress, alice_stash.substrateAddress, 1000);
26-
expect((await context.provider.getBalance(alice.getAddress())).toString()).to.equal("8999999991609227300000000");
27-
expect((await context.provider.getBalance(alice_stash.getAddress())).toString()).to.equal("10100000995648310012000000");
28-
expect((await context.provider.getBalance(alice.getAddress(), "latest")).toString()).to.equal("8999999991609227300000000");
26+
expect((await context.provider.getBalance(alice.getAddress())).toString()).to.equal("8999999990446773722000000");
27+
expect((await context.provider.getBalance(alice_stash.getAddress())).toString()).to.equal("10100000995072576531000000");
28+
expect((await context.provider.getBalance(alice.getAddress(), "latest")).toString()).to.equal("8999999990446773722000000");
2929
expect((await context.provider.getBalance(alice_stash.getAddress(), "earliest")).toString()).to.equal("0");
3030
});
3131
});

ts-tests/tests/test-evm-create-fill-block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ describeWithAcala("Acala RPC (EVM create fill block)", (context) => {
3535

3636
const evmCreateEvents = events.events.filter((item) => context.provider.api.events.evm.Created.is(item.event));
3737

38-
expect(evmCreateEvents.length).to.equal(225);
38+
expect(evmCreateEvents.length).to.equal(216);
3939
});
4040
});

ts-tests/tests/test-gas-limit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ describeWithAcala("Acala RPC (GasLimit)", (context) => {
1818
const contract = await deployContract(alice, Factory);
1919
// limited by used_storage
2020
const result = await contract.createContractLoop(350);
21-
expect(result.gasLimit.toNumber()).toMatchInlineSnapshot(`3928498122`);
21+
expect(result.gasLimit.toNumber()).toMatchInlineSnapshot(`3928198122`);
2222

2323
const result2 = await contract.incrementLoop(8130);
24-
expect(result2.gasLimit.toNumber()).toMatchInlineSnapshot(`32506508`);
24+
expect(result2.gasLimit.toNumber()).toMatchInlineSnapshot(`32206508`);
2525

2626
const storages = await context.provider.api.query.evm.accountStorages.entries(contract.address);
2727
// 350 array items

ts-tests/tests/test-mempool-priority.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ describeWithAcala("Acala RPC (Mempool Priority Order)", (context) => {
7070

7171
const operationalTransactionvalidity = await context.provider.api.call.taggedTransactionQueue.validateTransaction(
7272
"Local",
73-
tx3.toHex(),
73+
tx3.toU8a(),
7474
parentHash
7575
);
7676

7777
expect(operationalTransactionvalidity).toMatchInlineSnapshot(`
7878
{
7979
"ok": {
8080
"longevity": 31,
81-
"priority": "0x0119dfa51d01f600",
81+
"priority": "0x010543655f7f0900",
8282
"propagate": true,
8383
"provides": [
8484
"0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d03000000",
@@ -96,7 +96,7 @@ describeWithAcala("Acala RPC (Mempool Priority Order)", (context) => {
9696
await tx4.signAsync(alice.substrateAddress, { nonce: nonce + 2 });
9797
const normalTransactionvalidity = await context.provider.api.call.taggedTransactionQueue.validateTransaction(
9898
"Local",
99-
tx4.toHex(),
99+
tx4.toU8a(),
100100
parentHash
101101
);
102102
expect(normalTransactionvalidity.toHuman()).toMatchInlineSnapshot(`
@@ -120,7 +120,7 @@ describeWithAcala("Acala RPC (Mempool Priority Order)", (context) => {
120120
);
121121
const unsignedTransactionvalidity = await context.provider.api.call.taggedTransactionQueue.validateTransaction(
122122
"Local",
123-
tx5.toHex(),
123+
tx5.toU8a(),
124124
parentHash
125125
);
126126

ts-tests/tests/util.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Blockchain, BuildBlockMode, setupWithServer } from "@acala-network/chopsticks";
2-
import { BodhiProvider, BodhiSigner, getTestUtils } from "@acala-network/bodhi";
2+
import { BodhiProvider } from "@acala-network/eth-providers";
3+
import { BodhiSigner, getTestUtils } from "@acala-network/bodhi";
34
import { Option } from '@polkadot/types/codec';
45
import { EvmAccountInfo } from '@acala-network/types/interfaces';
56
import { AddressOrPair, SubmittableExtrinsic } from "@polkadot/api/types";
@@ -21,7 +22,7 @@ export async function startAcalaNode(sealing = true, autoClaim = true): Promise<
2122
'runtime-log-level': 0,
2223
});
2324

24-
const { provider, wallets } = await getTestUtils(`ws://127.0.0.1:${server.listenPort}`, autoClaim);
25+
const { provider, wallets } = await getTestUtils(`ws://${server.addr}`, autoClaim);
2526

2627
if (!sealing) {
2728
server.chain.txPool.mode = BuildBlockMode.Manual;
@@ -53,7 +54,7 @@ export function describeWithAcala(title: string, cb: (context: TestContext) => v
5354

5455
afterAll(async function () {
5556
// console.log(`\x1b[31m Killing RPC\x1b[0m`);
56-
await context.provider.api.disconnect()
57+
await context.provider.api.disconnect();
5758
await context.close();
5859
});
5960

ts-tests/vitest.config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export default defineConfig({
66
pool: 'forks',
77
passWithNoTests: true,
88
include: ['tests/**/test-*.{js,ts}'],
9+
setupFiles: ['./tests/setup.ts']
910
},
1011
})

0 commit comments

Comments
 (0)