-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add operational class test with normal and operational extrinsics
- Loading branch information
1 parent
6670a40
commit ea8fb61
Showing
12 changed files
with
82,947 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,16 @@ | ||
Description: Operational Class Test | ||
Network: ../network/operational_test.toml | ||
Creds: ./creds_empty_file | ||
|
||
# Metrics checks | ||
alice: reports node_roles is 4 | ||
alice: reports sub_libp2p_is_major_syncing is 0 | ||
|
||
# Log checks | ||
bob: log line matches glob "*rted #1*" within 10 seconds | ||
bob: log line matches "Imported #[0-9]+" within 10 seconds | ||
|
||
# Run scripts (relative paths assumed, adjust if needed) | ||
alice: run ./scripts/send_normal_tx.sh | ||
alice: run ./scripts/send_operational_extrinsic.sh | ||
alice: run ./scripts/send_asset_tradable_operational.sh |
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,13 @@ | ||
// query_asset_state.js | ||
const { ApiPromise, WsProvider } = require('@polkadot/api'); | ||
|
||
(async () => { | ||
const provider = new WsProvider('ws://127.0.0.1:PORT'); | ||
const api = await ApiPromise.create({ provider }); | ||
|
||
// Replace with the appropriate storage query | ||
const assetState = await api.query.omnipool.assetTradable(/* assetId */); | ||
|
||
console.log(`Asset tradable state: ${assetState}`); | ||
process.exit(0); | ||
})(); |
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,28 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# This script queries the chain's storage for the asset tradable state. | ||
# Adjust the RPC port and assetId as needed. | ||
|
||
PORT=45589 | ||
ASSET_ID=1 | ||
|
||
cat <<EOF > /tmp/query_asset_state.js | ||
const { ApiPromise, WsProvider } = require('@polkadot/api'); | ||
(async () => { | ||
const provider = new WsProvider('ws://127.0.0.1:$PORT'); | ||
const api = await ApiPromise.create({ provider }); | ||
// Adjust this query based on your runtime storage definition. | ||
// For example, if storage item is `Omnipool::AssetTradable` | ||
// and returns a bool or custom enum. | ||
const assetState = await api.query.omnipool.assetTradable($ASSET_ID); | ||
console.log(\`Asset \$ASSET_ID tradable state: \${assetState}\`); | ||
process.exit(0); | ||
})(); | ||
EOF | ||
|
||
node /tmp/query_asset_state.js |
36 changes: 36 additions & 0 deletions
36
integration-tests/tests/scripts/send_asset_tradable_operational.js
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 @@ | ||
#!/usr/bin/env node | ||
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api'); | ||
|
||
(async () => { | ||
const PORT = 45589; // Change this if needed | ||
const assetId = 1; // Replace with the actual asset ID | ||
const desiredState = true; // Replace with true/false depending on what you want | ||
|
||
const provider = new WsProvider(`ws://127.0.0.1:${PORT}`); | ||
const api = await ApiPromise.create({ provider }); | ||
|
||
// Create a keyring and add the sudo key (Alice) | ||
const keyring = new Keyring({ type: 'sr25519' }); | ||
const sudoKey = keyring.addFromUri('//Alice'); | ||
|
||
console.log('Sending operational extrinsic to set asset tradability...'); | ||
|
||
// Construct the call to set asset tradable state via the sudo pallet. | ||
// Make sure `setAssetTradableState` is the correct call and takes (assetId, bool). | ||
// If the call differs, adjust accordingly. | ||
const call = api.tx.omnipool.setAssetTradableState(assetId, desiredState); | ||
|
||
// Wrap the call with sudo | ||
const sudoCall = api.tx.sudo.sudo(call); | ||
|
||
// Sign and send the extrinsic | ||
const unsub = await sudoCall.signAndSend(sudoKey, (result) => { | ||
if (result.status.isInBlock) { | ||
console.log('Extrinsic included in block'); | ||
} else if (result.status.isFinalized) { | ||
console.log('Extrinsic finalized'); | ||
unsub(); | ||
process.exit(0); | ||
} | ||
}); | ||
})(); |
11 changes: 11 additions & 0 deletions
11
integration-tests/tests/scripts/send_asset_tradable_operational.sh
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,11 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# Write the JS code to a file in the ephemeral environment. | ||
# Adjust assetId, desiredState, and PORT as needed here too if you prefer inline substitutions. | ||
|
||
cat <<EOF > /tmp/send_asset_tradable_operational.js | ||
$(cat send_asset_tradable_operational.js) | ||
EOF | ||
|
||
node /tmp/send_asset_tradable_operational.js |
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,18 @@ | ||
// send_many_normal_txs.js | ||
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api'); | ||
|
||
(async () => { | ||
const provider = new WsProvider('ws://127.0.0.1:PORT'); // Adjust the port | ||
const api = await ApiPromise.create({ provider }); | ||
|
||
const keyring = new Keyring({ type: 'sr25519' }); | ||
const alice = keyring.addFromUri('//Alice'); | ||
|
||
console.log('Sending multiple normal txs...'); | ||
for (let i = 0; i < 100; i++) { | ||
const tx = api.tx.balances.transfer(alice.address, 1); | ||
await tx.signAndSend(alice, { nonce: -1 }); | ||
} | ||
console.log('Done sending normal transactions.'); | ||
process.exit(0); | ||
})(); |
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,29 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# This script sends multiple normal (non-operational) extrinsics. | ||
|
||
# Change this port if needed | ||
PORT=45589 | ||
|
||
cat <<EOF > /tmp/send_many_normal_txs.js | ||
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api'); | ||
(async () => { | ||
const provider = new WsProvider('ws://127.0.0.1:$PORT'); | ||
const api = await ApiPromise.create({ provider }); | ||
const keyring = new Keyring({ type: 'sr25519' }); | ||
const alice = keyring.addFromUri('//Alice'); | ||
console.log('Sending multiple normal transactions...'); | ||
for (let i = 0; i < 100; i++) { | ||
const tx = api.tx.balances.transfer(alice.address, 1); | ||
await tx.signAndSend(alice, { nonce: -1 }); | ||
} | ||
console.log('Done sending normal transactions.'); | ||
process.exit(0); | ||
})(); | ||
EOF | ||
|
||
node /tmp/send_many_normal_txs.js |
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,27 @@ | ||
// File: scripts/send_normal_txs.js | ||
// | ||
// Sends multiple normal (non-operational) extrinsics to saturate block weight. | ||
// Adjust the extrinsic and count as needed. For instance, sending small | ||
// balance transfers to self multiple times. | ||
|
||
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api'); | ||
|
||
(async () => { | ||
const args = process.argv.slice(2); | ||
const countIndex = args.indexOf("--count"); | ||
const count = countIndex !== -1 ? parseInt(args[countIndex+1]) : 100; | ||
|
||
const provider = new WsProvider('ws://127.0.0.1:45589'); // Adjust to your node RPC | ||
const api = await ApiPromise.create({ provider }); | ||
|
||
const keyring = new Keyring({ type: 'sr25519' }); | ||
const alice = keyring.addFromUri('//Alice'); | ||
|
||
for (let i = 0; i < count; i++) { | ||
const tx = api.tx.balances.transfer(alice.address, 1); // minimal non-operational tx | ||
await tx.signAndSend(alice, { nonce: -1 }); | ||
} | ||
|
||
console.log(`Sent ${count} normal transactions.`); | ||
process.exit(0); | ||
})(); |
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,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Write the JS code to a file in the ephemeral environment | ||
cat <<EOF > /tmp/send_normal_tx.js | ||
console.log("Sending normal transaction..."); | ||
// ... rest of your JS code here ... | ||
EOF | ||
|
||
# Now run it | ||
node /tmp/send_normal_tx.js |
Oops, something went wrong.