Skip to content

Commit

Permalink
test: improve speed of starknet integration tests 10x (#981)
Browse files Browse the repository at this point in the history
The issue is with starknetjs implementation of waitForTransaction,
that will always take at least 10s with default settings.

We can improve it a lot by just decreasing intervals.

starknet-io/starknet.js#1237 (comment)
  • Loading branch information
Sekhmet authored Nov 16, 2024
1 parent 71ae98e commit f57a435
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 22 additions & 8 deletions packages/sx.js/test/integration/starknet/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
increaseTime,
setTime,
setup,
sleep,
TestConfig
} from './utils';
import {
Expand All @@ -36,7 +37,10 @@ describe('sx-starknet', () => {
const privateKey = '0x9c7d498a8f76dc87564274036988f668';

const starkProvider = new RpcProvider({
nodeUrl: 'http://127.0.0.1:5050/rpc'
nodeUrl: 'http://127.0.0.1:5050/rpc',
// default is 5s and for some reason each call with call it 2 times (one before looking for receipt, and once after)
// this way it's quick (20s instead of 9 minutes)
transactionRetryIntervalFallback: 100
});

const provider = new JsonRpcProvider(ethUrl);
Expand Down Expand Up @@ -145,7 +149,8 @@ describe('sx-starknet', () => {
}
],
proposal: 1,
choice: Choice.For
choice: Choice.For,
metadataUri: ''
}
};

Expand Down Expand Up @@ -197,7 +202,8 @@ describe('sx-starknet', () => {
}
],
proposal: 2,
choice: Choice.For
choice: Choice.For,
metadataUri: ''
};

const envelope = await ethSigClient.vote({ signer: wallet, data });
Expand Down Expand Up @@ -256,7 +262,8 @@ describe('sx-starknet', () => {
}
],
proposal: 3,
choice: Choice.For
choice: Choice.For,
metadataUri: ''
};

await ethTxClient.initializeVote(wallet, data);
Expand Down Expand Up @@ -315,7 +322,8 @@ describe('sx-starknet', () => {
}
],
proposal: 4,
choice: Choice.For
choice: Choice.For,
metadataUri: ''
};

const envelope = await starkSigClient.vote({ signer: account, data });
Expand Down Expand Up @@ -375,7 +383,8 @@ describe('sx-starknet', () => {
}
],
proposal: 5,
choice: Choice.For
choice: Choice.For,
metadataUri: ''
}
};

Expand Down Expand Up @@ -436,7 +445,8 @@ describe('sx-starknet', () => {
}
],
proposal: 6,
choice: Choice.For
choice: Choice.For,
metadataUri: ''
}
};

Expand Down Expand Up @@ -495,10 +505,14 @@ describe('sx-starknet', () => {
}
],
proposal: 7,
choice: Choice.For
choice: Choice.For,
metadataUri: ''
}
};

// NOTE: to avoid Votes: future lookup
await sleep(10000);

const receipt = await client.vote(account, envelope);
console.log('Receipt', receipt);

Expand Down
4 changes: 4 additions & 0 deletions packages/sx.js/test/integration/starknet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,7 @@ export function loadL1MessagingContract(networkUrl: string, address: string) {
export function flush() {
return postDevnet('postman/flush', {});
}

export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

0 comments on commit f57a435

Please sign in to comment.