Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 22 additions & 5 deletions tests/tests/test-trace-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describeDevMoonbeam("Trace filter - Contract creation ", (context) => {
expect(response.result[0].type).to.equal("create");
});

it("Multiple transactions in the same block + trace over multiple blocks", async function () {
it("should be able to trace through multiple blocks", async function () {
// Perform RPC call.
let response = await customWeb3Request(context.web3, "trace_filter", [
{
Expand All @@ -112,7 +112,7 @@ describeDevMoonbeam("Trace filter - Contract creation ", (context) => {
expect(response.result[2].transactionPosition).to.equal(1);
});

it("Call with subcalls, some reverting", async function () {
it("should be able to trace sub-call with reverts", async function () {
// Perform RPC call.
let response = await customWeb3Request(context.web3, "trace_filter", [
{
Expand All @@ -138,7 +138,7 @@ describeDevMoonbeam("Trace filter - Contract creation ", (context) => {
expect(response.result[6].traceAddress).to.deep.equal([1, 1]);
});

it("Request range of blocks", async function () {
it("should support tracing range of blocks", async function () {
let response = await customWeb3Request(context.web3, "trace_filter", [
{
fromBlock: "0x03",
Expand Down Expand Up @@ -167,7 +167,7 @@ describeDevMoonbeam("Trace filter - Contract creation ", (context) => {
expect(response.result[8].transactionPosition).to.equal(0);
});

it("Filter fromAddress", async function () {
it("should support filtering trace per fromAddress", async function () {
let response = await customWeb3Request(context.web3, "trace_filter", [
{
fromBlock: "0x03",
Expand All @@ -179,7 +179,7 @@ describeDevMoonbeam("Trace filter - Contract creation ", (context) => {
expect(response.result.length).to.equal(3);
});

it("Filter toAddress", async function () {
it("should support filtering trace per toAddress", async function () {
let response = await customWeb3Request(context.web3, "trace_filter", [
{
fromBlock: "0x03",
Expand All @@ -190,4 +190,21 @@ describeDevMoonbeam("Trace filter - Contract creation ", (context) => {

expect(response.result.length).to.equal(4);
});

it("should handle pagination", async function () {
let response = await customWeb3Request(context.web3, "trace_filter", [
{
fromBlock: "0x03",
toBlock: "0x04",
count: 2,
after: 1,
},
]);

expect(response.result.length).to.equal(2);
expect(response.result[0].blockNumber).to.equal(3);
expect(response.result[0].transactionPosition).to.equal(1);
expect(response.result[1].blockNumber).to.equal(4);
expect(response.result[1].transactionPosition).to.equal(0);
});
});
13 changes: 5 additions & 8 deletions tests/util/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ export const provideWeb3Api = async (port: number, protocol: "ws" | "http" = "ht
};

export const providePolkadotApi = async (port: number) => {
const provider = new WsProvider(`ws://localhost:${port}`);
return {
provider,
apiPromise: await ApiPromise.create({
provider: provider,
typesBundle: typesBundle as any,
}),
};
return await ApiPromise.create({
initWasm: false,
provider: new WsProvider(`ws://localhost:${port}`),
typesBundle: typesBundle as any,
});
};

export const provideEthersApi = async (port: number) => {
Expand Down
33 changes: 16 additions & 17 deletions tests/util/setup-dev-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ export interface DevTestContext {
}

interface InternalDevTestContext extends DevTestContext {
polkadotWsProviders: WsProvider[];
web3Providers: HttpProvider[];

// Internal member to keep track of web3 singleton
_polkadotApi: EnhancedWeb3;
_polkadotApis: ApiPromise[];
_web3Providers: HttpProvider[];
}

export function describeDevMoonbeam(title: string, cb: (context: DevTestContext) => void) {
Expand Down Expand Up @@ -78,27 +75,30 @@ export function describeDevMoonbeam(title: string, cb: (context: DevTestContext)
// Context is given prior to this assignement, so doing
// context = init.context will fail because it replace the variable;

context.polkadotWsProviders = [];
context.web3Providers = [];
context._polkadotApis = [];
context._web3Providers = [];
moonbeamProcess = init.runningNode;

context.createWeb3 = async (protocol: "ws" | "http" = "http") => {
const provider =
protocol == "ws"
? await provideWeb3Api(init.wsPort, "ws")
: await provideWeb3Api(init.rpcPort, "http");
context.web3Providers.push((provider as any)._provider);
context._web3Providers.push((provider as any)._provider);
return provider;
};
context.createEthers = async () => provideEthersApi(init.rpcPort);
context.createPolkadotApi = async () => {
const { provider, apiPromise } = await providePolkadotApi(init.wsPort);
// We keep track of the polkadotWsProvider to close them at the end of the test
if (!context.polkadotWsProviders) {
context.polkadotWsProviders = [];
}
context.polkadotWsProviders.push(provider);
const apiPromise = await providePolkadotApi(init.wsPort);
// We keep track of the polkadotApis to close them at the end of the test
context._polkadotApis.push(apiPromise);
await apiPromise.isReady;
// Necessary hack to allow polkadotApi to finish its internal metadata loading
// apiPromise.isReady unfortunately doesn't wait for those properly
await new Promise((resolve) => {
setTimeout(resolve, 100);
});

return apiPromise;
};

Expand All @@ -121,9 +121,8 @@ export function describeDevMoonbeam(title: string, cb: (context: DevTestContext)
});

after(async function () {
// console.log(`\x1b[31m Killing RPC\x1b[0m`);
await Promise.all(context.web3Providers.map((p) => p.disconnect()));
await Promise.all(context.polkadotWsProviders.map((p) => p.disconnect()));
await Promise.all(context._web3Providers.map((p) => p.disconnect()));
await Promise.all(context._polkadotApis.map((p) => p.disconnect()));

if (moonbeamProcess) {
await new Promise((resolve) => {
Expand Down