Skip to content

Commit

Permalink
papi dev
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Nov 15, 2024
1 parent 510a501 commit 4f33360
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
strategy:
fail-fast: false
matrix:
suite: ["dev_test", "dev_multi", "dev_seq", "dev_smoke"]
suite: ["dev_test", "dev_multi", "dev_seq", "dev_smoke", "papi_dev"]
shard: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -142,6 +142,7 @@ jobs:
- name: Run ${{matrix.suite}} dev test
run: |
cd test
bun papi generate
bun moonwall test ${{matrix.suite}} --ts ${{ matrix.shard }}/4
test_chopsticks:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ artifacts

.idea
db.sqlite*
polkadot*
1 change: 0 additions & 1 deletion test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
**/node_modules/
**/dist/
test/html/*
*.sqlite
**/*.log
Expand Down
2 changes: 1 addition & 1 deletion test/.papi/descriptors/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-autogenerated.12090119445759399432",
"version": "0.1.0-autogenerated.14428066472396439845",
"name": "@polkadot-api/descriptors",
"files": [
"dist"
Expand Down
Binary file added test/.papi/metadata/mb.scale
Binary file not shown.
14 changes: 14 additions & 0 deletions test/.papi/polkadot-api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 0,
"descriptorPath": ".papi/descriptors",
"entries": {
"dot": {
"chain": "polkadot",
"metadata": ".papi/metadata/dot.scale"
},
"mb": {
"wsUrl": "ws://127.0.0.1:9955",
"metadata": ".papi/metadata/mb.scale"
}
}
}
3 changes: 1 addition & 2 deletions test/configs/zombie.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
],
"command": "tmp/moonbeam",
"name": "alith",
"ws_port": 33345

"ws_port": 33345
}
}
],
Expand Down
26 changes: 26 additions & 0 deletions test/moonwall.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,32 @@
"endpoints": ["wss://rpc.polkadot.io"]
}
]
},
{
"name": "papi_dev",
"testFileDir": ["suites/papi"],
"include": ["**/dev*"],
"envVars": [""],
"foundation": {
"type": "dev",
"launchSpec": [
{
"name": "moonbeam",
"running": true,
"binPath": "./tmp/moonbeam",
"ports": {
"rpcPort": 9955
}
}
]
},
"connections": [
{
"name": "papi",
"type": "papi",
"endpoints": ["ws://127.0.0.1:9955"]
}
]
}
]
}
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"fmt:fix": "biome format . --write",
"node_test": "node --no-warnings --loader tsx --test suites/node_test/*.ts",
"bun_test": "bun test suites/bun_test/*",
"papi": "papi"
"postinstall": "papi"
},
"devDependencies": {
"@acala-network/chopsticks": "*",
Expand Down
4 changes: 2 additions & 2 deletions test/scripts/failing-script.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
console.log("This script will fail on purpose.")
console.log("This script will fail on purpose.");

process.exit(1)
process.exit(1);
3 changes: 1 addition & 2 deletions test/suites/dummy-smoke/test_block_finalized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ describeSuite({
it({
id: "C300",
title: `should have only finalized blocks in the past ${(
timePeriod /
(1000 * 60 * 60)
timePeriod / (1000 * 60 * 60)
).toFixed(2)} hours #C300`,
test: async function () {
this.timeout(timeout);
Expand Down
19 changes: 9 additions & 10 deletions test/suites/multi_chopsticks/test_multi_chop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ describeSuite({
id: "T01",
title: "Verify multiple chains connected",
test: async () => {
const chain1Name = context.polkadotJs("hydration").consts.system.version.specName.toString();
const chain2Name = context
.polkadotJs("assethub")
const chain1Name = context
.polkadotJs("hydration")
.consts.system.version.specName.toString();
const chain2Name = context.polkadotJs("assethub").consts.system.version.specName.toString();
const chain3Name = context.polkadotJs("polkadot").consts.system.version.specName.toString();

expect(chain1Name).toBe("hydradx");
Expand All @@ -29,17 +29,17 @@ describeSuite({
await context.polkadotJs("hydration").rpc.chain.getHeader()
).number.toNumber();
await context.createBlock({ providerName: "hydration" });
expect((await context.polkadotJs("hydration").rpc.chain.getHeader()).number.toNumber()).toBe(
chain1Height + 1
);
expect(
(await context.polkadotJs("hydration").rpc.chain.getHeader()).number.toNumber()
).toBe(chain1Height + 1);

const chain2Height = (
await context.polkadotJs("assethub").rpc.chain.getHeader()
).number.toNumber();
await context.createBlock({ providerName: "assethub" });
expect(
(await context.polkadotJs("assethub").rpc.chain.getHeader()).number.toNumber()
).toBe(chain2Height + 1);
expect((await context.polkadotJs("assethub").rpc.chain.getHeader()).number.toNumber()).toBe(
chain2Height + 1
);

const chain3Height = (
await context.polkadotJs("polkadot").rpc.chain.getHeader()
Expand All @@ -50,6 +50,5 @@ describeSuite({
);
},
});

},
});
41 changes: 41 additions & 0 deletions test/suites/papi/dev.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describeSuite, expect, beforeAll, afterAll, customDevRpcRequest } from "@moonwall/cli";
import type { PolkadotClient, TypedApi } from "polkadot-api";
import { mb } from "@polkadot-api/descriptors";

describeSuite({
id: "P01",
title: "Polkadot API - Dev",
foundationMethods: "dev",
testCases: ({ it, context, log }) => {
let papi: PolkadotClient;
let api: TypedApi<typeof mb>;

beforeAll(async () => {
log("Should be before all test cases");
papi = context.papi();
api = await papi.getTypedApi(mb);
});

it({
id: "T1",
title: "Can connect to dev node",
test: async () => {
const { spec_name } = await api.constants.System.Version();
expect(spec_name.toString()).toBe("moonbase");
},
});

it({
id: "T2",
title: "Can query chain",
test: async () => {
const blockbefore = await api.query.System.Number.getValue();

await customDevRpcRequest("engine_createBlock", [true, true]);

const blockafter = await api.query.System.Number.getValue();
expect(blockafter).toBeGreaterThan(blockbefore);
},
});
},
});
6 changes: 3 additions & 3 deletions test/suites/papi/read_only.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describeSuite, expect, beforeAll, afterAll } from "@moonwall/cli";
import type { PolkadotClient } from "polkadot-api";
import { dot } from "@polkadot-api/descriptors";
import { dot } from "@polkadot-api/descriptors";

describeSuite({
id: "P01",
Expand Down Expand Up @@ -67,11 +67,11 @@ describeSuite({
id: "T5",
title: "Can get safeApi ",
test: async () => {
const safeApi = await context.papi().getTypedApi(dot)
const safeApi = await context.papi().getTypedApi(dot);
expect(safeApi).not.toBeNull();
const block = await safeApi.query.System.Number.getValue();
expect(block).toBeGreaterThan(0);
},
})
});
},
});
14 changes: 9 additions & 5 deletions test/suites/zombie/test_basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,25 @@ describeSuite({
title: "Restart a node from test script",
timeout: 240000,
test: async () => {
const initialHeight = (await context.polkadotJs("parachain").rpc.chain.getHeader()).number.toNumber();
const initialHeight = (
await context.polkadotJs("parachain").rpc.chain.getHeader()
).number.toNumber();
console.log("Initial height", initialHeight);
await context.restartNode("alith");
console.log("Node restarted");

const newApi = await ApiPromise.create({provider: new WsProvider("ws://localhost:33345")});
const newApi = await ApiPromise.create({
provider: new WsProvider("ws://localhost:33345"),
});

for (; ;) {
for (;;) {
const newHeight = (await newApi.rpc.chain.getHeader()).number.toNumber();
console.log("New height", newHeight);
if (newHeight > initialHeight + 1) {
break;
}
}
}
})
},
});
},
});
2 changes: 0 additions & 2 deletions test/suites/zombieNoPara/test_basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,5 @@ describeSuite({
expect(network).to.contain("rococo");
},
});


},
});

0 comments on commit 4f33360

Please sign in to comment.