-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zombienet): Add javascript tests to zombienet testing (#3200)
- Loading branch information
1 parent
db0be3f
commit aca9a5b
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[relaychain] | ||
chain_spec_path = "chain/westend-local/westend-local-spec-raw.json" | ||
|
||
chain = "westend-local" | ||
|
||
[[relaychain.nodes]] | ||
name = "alice" | ||
command = "gossamer" | ||
validator = true | ||
args = ["--key alice"] | ||
|
||
[[relaychain.nodes]] | ||
name = "bob" | ||
command = "gossamer" | ||
validator = true | ||
args = ["--key bob"] | ||
|
||
[[relaychain.nodes]] | ||
name = "charlie" | ||
command = "gossamer" | ||
validator = true | ||
args = ["--key charlie"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Description: Small Network test | ||
Network: ./0002-basic-network.toml | ||
Creds: config | ||
|
||
# well know functions | ||
alice: is up | ||
bob: is up | ||
|
||
{% set nodes = ["alice", "bob", "charlie"] %} | ||
|
||
{% set nodeAddresses = ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", | ||
"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y"] %} | ||
|
||
# Check nodes are up, synced and have expected beginning balances | ||
{% for node in nodes %} | ||
{{node}}: is up | ||
{{node}}: reports gossamer_network_syncer_is_synced is 1 within 30 seconds | ||
|
||
{% for address in nodeAddresses %} | ||
{{node}}: js-script ./scripts/free-balance.js with "{{address}}" return is equal to 1000000000000000000 | ||
{% endfor %} | ||
{% endfor %} | ||
|
||
# Test transfer from Alice to Bob, NOTE: this is currently failing because nodes are not finalizing blocks | ||
alice: js-script ./scripts/transfer-tokens.js with "Alice,Bob" return is equal to 1 within 200 seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright 2023 ChainSafe Systems (ON) | ||
* SPDX-License-Identifier: LGPL-3.0-only | ||
*/ | ||
|
||
async function run(nodeName, networkInfo, args) { | ||
const {wsUri, userDefinedTypes} = networkInfo.nodesByName[nodeName]; | ||
const api = await zombie.connect(wsUri, userDefinedTypes); | ||
|
||
const {nonce, data: balance} = await api.query.system.account(args[0]); | ||
|
||
return balance.free; | ||
} | ||
|
||
module.exports = { run } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright 2023 ChainSafe Systems (ON) | ||
* SPDX-License-Identifier: LGPL-3.0-only | ||
*/ | ||
|
||
async function run(nodeName, networkInfo, args) { | ||
const { sendTransaction } = await import("./tx-utils.mjs"); | ||
const {wsUri, userDefinedTypes} = networkInfo.nodesByName[nodeName]; | ||
const api = await zombie.connect(wsUri, userDefinedTypes); | ||
|
||
await zombie.util.cryptoWaitReady(); | ||
|
||
// account to submit tx | ||
const keyring = new zombie.Keyring({ type: "sr25519" }); | ||
const FROM = keyring.addFromUri("//" + args[0]); | ||
const TO = keyring.addFromUri("//" + args[1]); | ||
const AMOUNT = 1000000000000000; | ||
|
||
const originalBalance = await api.query.system.account(TO.address); | ||
console.log('originalBalance', originalBalance.toString()); | ||
|
||
await sendTransaction( | ||
api.tx.balances.transfer({ Id: TO.address }, AMOUNT), | ||
FROM | ||
); | ||
|
||
const newBalance = await api.query.system.account(TO.address); | ||
console.log('newBalance', newBalance.toString()); | ||
|
||
const difference = newBalance.data.free - originalBalance.data.free | ||
const result = difference === AMOUNT ? 1 : 0 | ||
|
||
return result; | ||
} | ||
|
||
module.exports = { run } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright 2023 ChainSafe Systems (ON) | ||
* SPDX-License-Identifier: LGPL-3.0-only | ||
*/ | ||
|
||
export async function sendTransaction(transaction, sender) { | ||
return new Promise((resolve, reject) => { | ||
let unsubscribe; | ||
let timeout; | ||
const SPAWNING_TIME = 500000; | ||
|
||
transaction.signAndSend(sender, async (result) => { | ||
console.log(`Current status is ${result?.status}`); | ||
|
||
if (result.isFinalized) { | ||
if (unsubscribe) { | ||
unsubscribe(); | ||
} | ||
|
||
clearTimeout(timeout); | ||
resolve(true); | ||
} | ||
}).then(unsub => { | ||
unsubscribe = unsub; | ||
}).catch(error => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
|
||
timeout = setTimeout(() => { | ||
reject(new Error('Transaction timeout')); | ||
}, SPAWNING_TIME); | ||
}); | ||
} |