From fb7f10b377ef11ce6ef0aabe027c901ec338fbb3 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Fri, 7 Apr 2023 13:02:39 -0400 Subject: [PATCH 1/7] add basic javascript tests --- .../functional/0002-basic-network.toml | 22 +++++++++++++ .../functional/0002-basic-network.zndsl | 13 ++++++++ .../functional/scripts/free-balance.js | 10 ++++++ .../functional/scripts/transfer-tokens.js | 31 +++++++++++++++++++ .../functional/scripts/tx-utils.mjs | 29 +++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 zombienet_tests/functional/0002-basic-network.toml create mode 100644 zombienet_tests/functional/0002-basic-network.zndsl create mode 100644 zombienet_tests/functional/scripts/free-balance.js create mode 100644 zombienet_tests/functional/scripts/transfer-tokens.js create mode 100644 zombienet_tests/functional/scripts/tx-utils.mjs diff --git a/zombienet_tests/functional/0002-basic-network.toml b/zombienet_tests/functional/0002-basic-network.toml new file mode 100644 index 0000000000..12bff37ef4 --- /dev/null +++ b/zombienet_tests/functional/0002-basic-network.toml @@ -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", "--babe-lead"] + +[[relaychain.nodes]] +name = "bob" +command = "gossamer" +validator = true +args = ["--key bob"] + +[[relaychain.nodes]] +name = "charlie" +command = "gossamer" +validator = true +args = ["--key charlie"] diff --git a/zombienet_tests/functional/0002-basic-network.zndsl b/zombienet_tests/functional/0002-basic-network.zndsl new file mode 100644 index 0000000000..c1d3d82518 --- /dev/null +++ b/zombienet_tests/functional/0002-basic-network.zndsl @@ -0,0 +1,13 @@ +Description: Small Network test +Network: ./0002-basic-network.toml +Creds: config + +# well know functions +alice: is up +bob: is up + +alice: js-script ./scripts/free-balance.js with "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" return is equal to 1000000000000000000 + +alice: js-script ./scripts/free-balance.js with "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" return is equal to 1000000000000000000 + +alice: js-script ./scripts/transfer-tokens.js with "Alice,Bob" return is equal to 1 within 200 seconds \ No newline at end of file diff --git a/zombienet_tests/functional/scripts/free-balance.js b/zombienet_tests/functional/scripts/free-balance.js new file mode 100644 index 0000000000..4f8537ed32 --- /dev/null +++ b/zombienet_tests/functional/scripts/free-balance.js @@ -0,0 +1,10 @@ +async function run(nodeName, networkInfo, args) { + const {wsUri, userDefinedTypes} = networkInfo.nodesByName[nodeName]; + const api = await zombie.connect(wsUri, userDefinedTypes); + const ADDR = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; + const {nonce, data: balance} = await api.query.system.account(args[0]); + + return balance.free; +} + +module.exports = { run } \ No newline at end of file diff --git a/zombienet_tests/functional/scripts/transfer-tokens.js b/zombienet_tests/functional/scripts/transfer-tokens.js new file mode 100644 index 0000000000..1c85aeb3af --- /dev/null +++ b/zombienet_tests/functional/scripts/transfer-tokens.js @@ -0,0 +1,31 @@ +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 } \ No newline at end of file diff --git a/zombienet_tests/functional/scripts/tx-utils.mjs b/zombienet_tests/functional/scripts/tx-utils.mjs new file mode 100644 index 0000000000..32230a4870 --- /dev/null +++ b/zombienet_tests/functional/scripts/tx-utils.mjs @@ -0,0 +1,29 @@ +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); + }); +} \ No newline at end of file From fb45bb71425c78af49d04322263010837d5e2efa Mon Sep 17 00:00:00 2001 From: edwardmack Date: Mon, 10 Apr 2023 10:20:59 -0400 Subject: [PATCH 2/7] modify tests to use for loop --- dot/network/service.go | 1 + dot/rpc/modules/state.go | 1 + .../functional/0002-basic-network.zndsl | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/dot/network/service.go b/dot/network/service.go index fd0de70f95..d9fbb54b74 100644 --- a/dot/network/service.go +++ b/dot/network/service.go @@ -340,6 +340,7 @@ func (s *Service) Start() error { logger.Info("started network service with supported protocols " + strings.Join(s.host.protocols(), ", ")) if s.Metrics.Publish { + // TODO(ed) remove before commit processStartTimeGauge.Set(float64(time.Now().Unix())) go s.updateMetrics() } diff --git a/dot/rpc/modules/state.go b/dot/rpc/modules/state.go index 6266dfcd8e..a3bf0b46b7 100644 --- a/dot/rpc/modules/state.go +++ b/dot/rpc/modules/state.go @@ -500,6 +500,7 @@ func (sm *StateModule) QueryStorage( // QueryStorageAt queries historical storage entries (by key) at the block hash given or // the best block if the given block hash is nil +// TODO(ed): remove before merge into development after PR #3191 has been merged func (sm *StateModule) QueryStorageAt( _ *http.Request, request *StateStorageQueryAtRequest, response *[]StorageChangeSetResponse) error { atBlockHash := request.At diff --git a/zombienet_tests/functional/0002-basic-network.zndsl b/zombienet_tests/functional/0002-basic-network.zndsl index c1d3d82518..e01ed57f7e 100644 --- a/zombienet_tests/functional/0002-basic-network.zndsl +++ b/zombienet_tests/functional/0002-basic-network.zndsl @@ -6,8 +6,20 @@ Creds: config alice: is up bob: is up -alice: js-script ./scripts/free-balance.js with "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" return is equal to 1000000000000000000 +{% set nodes = ["alice", "bob", "charlie"] %} -alice: js-script ./scripts/free-balance.js with "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" return is equal to 1000000000000000000 +{% set nodeAddresses = ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", +"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y"] %} +# Check nodes are up, syncing 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 %} + alice: 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 \ No newline at end of file From a8f1128e34987f427558ed0f4a9b6975fc900901 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Mon, 10 Apr 2023 10:33:07 -0400 Subject: [PATCH 3/7] remove un-used line --- zombienet_tests/functional/scripts/free-balance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zombienet_tests/functional/scripts/free-balance.js b/zombienet_tests/functional/scripts/free-balance.js index 4f8537ed32..7781318467 100644 --- a/zombienet_tests/functional/scripts/free-balance.js +++ b/zombienet_tests/functional/scripts/free-balance.js @@ -1,7 +1,7 @@ async function run(nodeName, networkInfo, args) { const {wsUri, userDefinedTypes} = networkInfo.nodesByName[nodeName]; const api = await zombie.connect(wsUri, userDefinedTypes); - const ADDR = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; + const {nonce, data: balance} = await api.query.system.account(args[0]); return balance.free; From 7b346d1bc04886c62b17abe3923d89feb7eee5d6 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Mon, 10 Apr 2023 10:57:49 -0400 Subject: [PATCH 4/7] add copyright notice --- zombienet_tests/functional/scripts/free-balance.js | 5 +++++ zombienet_tests/functional/scripts/transfer-tokens.js | 5 +++++ zombienet_tests/functional/scripts/tx-utils.mjs | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/zombienet_tests/functional/scripts/free-balance.js b/zombienet_tests/functional/scripts/free-balance.js index 7781318467..d707697bc5 100644 --- a/zombienet_tests/functional/scripts/free-balance.js +++ b/zombienet_tests/functional/scripts/free-balance.js @@ -1,3 +1,8 @@ +/** + * 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); diff --git a/zombienet_tests/functional/scripts/transfer-tokens.js b/zombienet_tests/functional/scripts/transfer-tokens.js index 1c85aeb3af..dbea9f5324 100644 --- a/zombienet_tests/functional/scripts/transfer-tokens.js +++ b/zombienet_tests/functional/scripts/transfer-tokens.js @@ -1,3 +1,8 @@ +/** + * 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]; diff --git a/zombienet_tests/functional/scripts/tx-utils.mjs b/zombienet_tests/functional/scripts/tx-utils.mjs index 32230a4870..5540cedf21 100644 --- a/zombienet_tests/functional/scripts/tx-utils.mjs +++ b/zombienet_tests/functional/scripts/tx-utils.mjs @@ -1,3 +1,8 @@ +/** + * 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; From 49b96a6c18e1c3641e35135e35524a0e7328a6c5 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Thu, 13 Apr 2023 15:30:33 -0400 Subject: [PATCH 5/7] remove use of --babe-lead flag --- zombienet_tests/functional/0002-basic-network.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zombienet_tests/functional/0002-basic-network.toml b/zombienet_tests/functional/0002-basic-network.toml index 12bff37ef4..006a291856 100644 --- a/zombienet_tests/functional/0002-basic-network.toml +++ b/zombienet_tests/functional/0002-basic-network.toml @@ -7,7 +7,7 @@ chain = "westend-local" name = "alice" command = "gossamer" validator = true -args = ["--key alice", "--babe-lead"] +args = ["--key alice"] [[relaychain.nodes]] name = "bob" From 8e16f6621792389c196552cd80e2370d19516802 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Thu, 13 Apr 2023 15:35:24 -0400 Subject: [PATCH 6/7] update use of {{node}} var --- zombienet_tests/functional/0002-basic-network.zndsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zombienet_tests/functional/0002-basic-network.zndsl b/zombienet_tests/functional/0002-basic-network.zndsl index e01ed57f7e..1b71510544 100644 --- a/zombienet_tests/functional/0002-basic-network.zndsl +++ b/zombienet_tests/functional/0002-basic-network.zndsl @@ -11,13 +11,13 @@ bob: is up {% set nodeAddresses = ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y"] %} -# Check nodes are up, syncing and have expected beginning balances +# 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 %} - alice: js-script ./scripts/free-balance.js with "{{address}}" return is equal to 1000000000000000000 + {{node}}: js-script ./scripts/free-balance.js with "{{address}}" return is equal to 1000000000000000000 {% endfor %} {% endfor %} From f9df7f21944ef876edfc0ce40a55c11aca22a216 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Wed, 17 May 2023 10:21:21 -0400 Subject: [PATCH 7/7] remove completed TODO comments --- dot/network/service.go | 1 - dot/rpc/modules/state.go | 1 - 2 files changed, 2 deletions(-) diff --git a/dot/network/service.go b/dot/network/service.go index d9fbb54b74..fd0de70f95 100644 --- a/dot/network/service.go +++ b/dot/network/service.go @@ -340,7 +340,6 @@ func (s *Service) Start() error { logger.Info("started network service with supported protocols " + strings.Join(s.host.protocols(), ", ")) if s.Metrics.Publish { - // TODO(ed) remove before commit processStartTimeGauge.Set(float64(time.Now().Unix())) go s.updateMetrics() } diff --git a/dot/rpc/modules/state.go b/dot/rpc/modules/state.go index a3bf0b46b7..6266dfcd8e 100644 --- a/dot/rpc/modules/state.go +++ b/dot/rpc/modules/state.go @@ -500,7 +500,6 @@ func (sm *StateModule) QueryStorage( // QueryStorageAt queries historical storage entries (by key) at the block hash given or // the best block if the given block hash is nil -// TODO(ed): remove before merge into development after PR #3191 has been merged func (sm *StateModule) QueryStorageAt( _ *http.Request, request *StateStorageQueryAtRequest, response *[]StorageChangeSetResponse) error { atBlockHash := request.At