Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix runtime upgrade test by using governance instead of SUDO #924

Merged
merged 41 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d648933
Migrate runtime-upgrade test to mocha
ghzlatarev Dec 14, 2022
7494c5e
Bump spec-version for test
ghzlatarev Dec 14, 2022
8f131bd
Add trigger
ghzlatarev Dec 14, 2022
72be02a
use wget properlt to download last release binary
ghzlatarev Dec 14, 2022
4f42243
Fix missing config-for-runtime-upgrade-test
ghzlatarev Dec 14, 2022
ff66bc0
Fix directory
ghzlatarev Dec 14, 2022
8554aee
CLean up
ghzlatarev Dec 14, 2022
17edb0c
Fix test
ghzlatarev Dec 14, 2022
d3b4cf1
Get rid of testnet-ci chain-specs
ghzlatarev Dec 14, 2022
e9753fa
Use object for referendumIndex
ghzlatarev Dec 15, 2022
495a523
Use object for referendumIndex
ghzlatarev Dec 15, 2022
34352b7
Use object for referendumIndex
ghzlatarev Dec 15, 2022
2255d66
Clean up
ghzlatarev Dec 15, 2022
912055f
Clean up
ghzlatarev Dec 15, 2022
6fa15c4
Check
ghzlatarev Dec 15, 2022
eccd7d0
Check
ghzlatarev Dec 15, 2022
57ee3cc
Check
ghzlatarev Dec 15, 2022
1e9df46
Check
ghzlatarev Dec 15, 2022
c0377ce
Check
ghzlatarev Dec 15, 2022
be51dbd
Check
ghzlatarev Dec 15, 2022
4d3d91e
Check
ghzlatarev Dec 15, 2022
2b51336
Fix runtime upgrade code
ghzlatarev Dec 15, 2022
84a1a53
Clean up
ghzlatarev Dec 15, 2022
0299152
Clean up
ghzlatarev Dec 15, 2022
66befb4
Clean up
ghzlatarev Dec 15, 2022
2f8933a
Update all ci workflows
ghzlatarev Dec 15, 2022
801221e
Update all ci workflows
ghzlatarev Dec 15, 2022
a7656ad
Increase wait time
ghzlatarev Dec 15, 2022
5b97910
Bump timeout
ghzlatarev Dec 15, 2022
b893092
Bump timeout
ghzlatarev Dec 15, 2022
4308aac
Switch to -local
ghzlatarev Dec 15, 2022
852d666
Upload 9921 log
ghzlatarev Dec 17, 2022
a6d90b8
Update runtime-upgrade resource
ghzlatarev Dec 17, 2022
2177de8
Remove unused code
ghzlatarev Dec 17, 2022
b3afca7
Check block production in mocha test
ghzlatarev Dec 17, 2022
fdeb58c
Revert spec_version bumps that were for testing only
ghzlatarev Dec 17, 2022
87d4b9c
Merge branch 'manta' into ghzlatarev/update-rtu
ghzlatarev Dec 17, 2022
1de5eb7
Merge branch 'manta' into ghzlatarev/update-rtu
ghzlatarev Dec 18, 2022
351a2de
Merge branch 'manta' into ghzlatarev/update-rtu
ghzlatarev Dec 19, 2022
e7a6487
fix duplicate line
ferrell-code Dec 19, 2022
9317948
Merge branch 'manta' into ghzlatarev/update-rtu
Dec 20, 2022
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
5 changes: 5 additions & 0 deletions .github/resources/config-for-runtime-upgrade-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
{
"nodes": [
{
"name": "alice",
"wsPort": 9921,
"port": 32331,
"flags": [
Expand All @@ -61,6 +62,7 @@
]
},
{
"name": "bob",
"wsPort": 9922,
"port": 32332,
"flags": [
Expand All @@ -74,6 +76,7 @@
]
},
{
"name": "charlie",
"wsPort": 9923,
"port": 32333,
"flags": [
Expand All @@ -87,6 +90,7 @@
]
},
{
"name": "dave",
"wsPort": 9924,
"port": 32334,
"flags": [
Expand All @@ -100,6 +104,7 @@
]
},
{
"name": "eve",
"wsPort": 9925,
"port": 32335,
"flags": [
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/integration_test_calamari.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ env:
AWS_INSTANCE_ROOT_VOLUME_SIZE: 32
AWS_IMAGE_SEARCH_PATTERN: ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*
AWS_IMAGE_SEARCH_OWNERS: '["099720109477"]'
POLKADOT_BINARY: https://github.com/paritytech/polkadot/releases/download/v0.9.33/polkadot
jobs:
print-rust-versions:
if: contains(github.event.pull_request.labels.*.name, 'A-calamari' || github.ref == 'refs/heads/manta')
Expand Down Expand Up @@ -148,7 +149,7 @@ jobs:
ls -ahl $HOME/.local/bin/
- name: fetch and chmod polkadot
run: |
curl -L -o $HOME/.local/bin/polkadot https://github.com/paritytech/polkadot/releases/download/v0.9.26/polkadot
curl -L -o $HOME/.local/bin/polkadot ${{ env.POLKADOT_BINARY }}
chmod +x $HOME/.local/bin/polkadot
ls -ahl $HOME/.local/bin/
- id: create-chainspec
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/integration_test_dolphin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ env:
AWS_INSTANCE_ROOT_VOLUME_SIZE: 32
AWS_IMAGE_SEARCH_PATTERN: ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*
AWS_IMAGE_SEARCH_OWNERS: '["099720109477"]'
POLKADOT_BINARY: https://github.com/paritytech/polkadot/releases/download/v0.9.33/polkadot
jobs:
print-rust-versions:
if: contains(github.event.pull_request.labels.*.name, 'A-dolphin' || github.ref == 'refs/heads/manta')
Expand Down Expand Up @@ -148,7 +149,7 @@ jobs:
ls -ahl $HOME/.local/bin/
- name: fetch and chmod polkadot
run: |
curl -L -o $HOME/.local/bin/polkadot https://github.com/paritytech/polkadot/releases/download/v0.9.26/polkadot
curl -L -o $HOME/.local/bin/polkadot ${{ env.POLKADOT_BINARY }}
chmod +x $HOME/.local/bin/polkadot
ls -ahl $HOME/.local/bin/
- id: create-chainspec
Expand Down
218 changes: 21 additions & 197 deletions .github/workflows/runtime_upgrade_test.yml

Large diffs are not rendered by default.

83 changes: 0 additions & 83 deletions genesis/calamari-testnet-ci-genesis.json

This file was deleted.

110 changes: 0 additions & 110 deletions genesis/dolphin-testnet-ci-genesis.json

This file was deleted.

85 changes: 0 additions & 85 deletions genesis/manta-testnet-ci-genesis.json

This file was deleted.

7 changes: 0 additions & 7 deletions node/src/chain_specs/calamari.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,6 @@ pub fn calamari_testnet_config() -> Result<CalamariChainSpec, String> {
Ok(spec)
}

/// Returns the Calamari testnet for CI chainspec.
pub fn calamari_testnet_ci_config() -> Result<CalamariChainSpec, String> {
CalamariChainSpec::from_json_bytes(
&include_bytes!("../../../genesis/calamari-testnet-ci-genesis.json")[..],
)
}

/// Returns the Calamari mainnet chainspec.
pub fn calamari_config() -> Result<CalamariChainSpec, String> {
CalamariChainSpec::from_json_bytes(
Expand Down
8 changes: 0 additions & 8 deletions node/src/chain_specs/dolphin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,6 @@ pub fn dolphin_2085_config() -> Result<DolphinChainSpec, String> {
Ok(spec)
}

pub fn dolphin_testnet_ci_config() -> Result<DolphinChainSpec, String> {
let mut spec = DolphinChainSpec::from_json_bytes(
&include_bytes!("../../../genesis/dolphin-testnet-ci-genesis.json")[..],
)?;
spec.extensions_mut().para_id = DOLPHIN_PARACHAIN_ID;
Ok(spec)
}

/// Returns the Dolphin V3 2085 staging chainspec.
pub fn dolphin_v3_2085_staging_config() -> Result<DolphinChainSpec, String> {
let mut spec = DolphinChainSpec::from_json_bytes(
Expand Down
9 changes: 0 additions & 9 deletions node/src/chain_specs/manta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,6 @@ pub fn manta_testnet_config() -> Result<MantaChainSpec, String> {
Ok(spec)
}

/// Returns the Manta testnet for CI chainspec.
pub fn manta_testnet_ci_config() -> Result<MantaChainSpec, String> {
let mut spec = MantaChainSpec::from_json_bytes(
&include_bytes!("../../../genesis/manta-testnet-ci-genesis.json")[..],
)?;
spec.extensions_mut().para_id = MANTA_PARACHAIN_ID;
Ok(spec)
}

/// Returns the Manta mainnet chainspec.
pub fn manta_config() -> Result<MantaChainSpec, String> {
MantaChainSpec::from_json_bytes(&include_bytes!("../../../genesis/manta-genesis.json")[..])
Expand Down
3 changes: 0 additions & 3 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,17 @@ fn load_spec(id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
"manta-dev" => Ok(Box::new(chain_specs::manta_development_config())),
"manta-local" => Ok(Box::new(chain_specs::manta_local_config())),
"manta-testnet" => Ok(Box::new(chain_specs::manta_testnet_config()?)),
"manta-testnet-ci" => Ok(Box::new(chain_specs::manta_testnet_ci_config()?)),
"manta" => Ok(Box::new(chain_specs::manta_config()?)),
// calamari chainspec
"calamari-dev" => Ok(Box::new(chain_specs::calamari_development_config())),
"calamari-local" => Ok(Box::new(chain_specs::calamari_local_config())),
"calamari-testnet" => Ok(Box::new(chain_specs::calamari_testnet_config()?)),
"calamari-testnet-ci" => Ok(Box::new(chain_specs::calamari_testnet_ci_config()?)),
"calamari" => Ok(Box::new(chain_specs::calamari_config()?)),
// dolphin chainspec
"dolphin-dev" => Ok(Box::new(chain_specs::dolphin_development_config())),
"dolphin-local" => Ok(Box::new(chain_specs::dolphin_local_config())),
"dolphin-testnet" => Ok(Box::new(chain_specs::dolphin_testnet_config()?)),
"dolphin-2085" => Ok(Box::new(chain_specs::dolphin_2085_config()?)),
"dolphin-testnet-ci" => Ok(Box::new(chain_specs::dolphin_testnet_ci_config()?)),
"dolphin-v3-staging" => Ok(Box::new(chain_specs::dolphin_v3_2085_staging_config()?)),
path => {
let chain_spec = chain_specs::ChainSpec::from_json_file(path.into())?;
Expand Down
42 changes: 21 additions & 21 deletions tests/manta_pay.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiPromise } from '@polkadot/api';
import { KeyringPair } from '@polkadot/keyring/types';
import { u8aToHex, numberToU8a } from '@polkadot/util';
import { blake2AsHex } from "@polkadot/util-crypto";
import { u8aToHex, numberToU8a } from '@polkadot/util';
import { single_map_storage_key, double_map_storage_key, delay, HashType } from './test-util';

// number of shards at MantaPay
Expand All @@ -13,7 +13,7 @@ export const manta_pay_config = {

/**
* generate utxo deterministically using shard_idx and utxo_idx.
* @param shard_idx shard_idx of generated utxo.
* @param shard_idx shard_idx of generated utxo.
* @param utxo_idx utxo_idx within shard
* @returns a Shards entry of size 370 bytes
*/
Expand Down Expand Up @@ -41,7 +41,7 @@ export function generate_nullifier_set_entry(index: number): Uint8Array {
* @returns moved checkpoint.
*/
function next_checkpoint(
per_shard_amount: number,
per_shard_amount: number,
checkpoint: Array<number> ): Array<number>
{
if (checkpoint.length !== manta_pay_config.shard_number) {
Expand Down Expand Up @@ -72,7 +72,7 @@ function generate_batched_utxos(per_shard_amount: number, checkpoint: Array<numb
data.push([shards_storage_key, value_str]);
}
}
const new_checkpoint = next_checkpoint(per_shard_amount, checkpoint);
const new_checkpoint = next_checkpoint(per_shard_amount, checkpoint);
return {data: data, checkpoint: new_checkpoint};
}

Expand All @@ -89,10 +89,10 @@ var referendumIndexObject = { referendumIndex: 0 };
* @returns number of batches successfully inserted.
*/
async function insert_utxos_in_batches(
api: ApiPromise,
api: ApiPromise,
keyring: KeyringPair,
batch_number: number,
per_shard_amount: number,
per_shard_amount: number,
init_checkpoint: Array<number>,
max_wait_time_sec: number ): Promise<number>
{
Expand All @@ -109,7 +109,7 @@ async function insert_utxos_in_batches(
execute_with_root_via_governance(api, keyring, callData, referendumIndexObject);
await delay(5000);
}

// wait all txs finalized
for(let i = 0; i < max_wait_time_sec; i ++){
await delay(1000);
Expand All @@ -130,7 +130,7 @@ async function insert_utxos_in_batches(
function generate_vn_insertion_data(
start_index: number,
amount_per_batch: number): string[][] {
const data = [];
const data = [];
for (let idx = start_index; idx < start_index + amount_per_batch; idx ++){
const vn_storage_key = single_map_storage_key(
"MantaPay", "NullifierSetInsertionOrder", idx, 64, HashType.TwoxConcat);
Expand All @@ -150,15 +150,15 @@ function generate_vn_insertion_data(
* @returns number of batches successfully inserted before timeout.
*/
async function insert_void_numbers_in_batch(
api:ApiPromise,
keyring: KeyringPair,
api:ApiPromise,
keyring: KeyringPair,
amount_per_batch: number,
batch_number: number,
batch_number: number,
start_index: number,
max_wait_time_sec: number): Promise<number>{

let success_batch = 0;
let sender_idx = start_index;
let sender_idx = start_index;
for(let batch_idx = 0; batch_idx < batch_number; batch_idx ++) {
console.log("start vn batch %i", batch_idx);
const data = generate_vn_insertion_data(sender_idx, amount_per_batch);
Expand All @@ -170,8 +170,8 @@ async function insert_void_numbers_in_batch(
// wait all txs finalized
for(let i =0; i < max_wait_time_sec; i++){
await delay(1000);
if (success_batch === batch_number) {
console.log("total wait: %i sec.", i + 1);
if (success_batch === batch_number) {
console.log("total wait: %i sec.", i + 1);
return success_batch;
}
}
Expand All @@ -183,7 +183,7 @@ export type StoragePrepareConfig = {
utxo_batch_number: number,
utxo_batch_size_per_shard: number,
vn_batch_number: number,
vn_batch_size: number,
vn_batch_size: number,
}

/**
Expand All @@ -195,10 +195,10 @@ export type StoragePrepareConfig = {
*/
export async function setup_storage(
api:ApiPromise,
keyring: KeyringPair,
init_utxo_idx: number,
keyring: KeyringPair,
init_utxo_idx: number,
config: StoragePrepareConfig) {

const receiver_checkpoint = new Array<number>(manta_pay_config.shard_number);
const check_idx = init_utxo_idx;
console.log(">>>>>>>>> UTXO INSERT START >>>>>>>>");
Expand All @@ -208,12 +208,12 @@ export async function setup_storage(
console.log("starting utxo idx: %i", receiver_checkpoint[0]);
const utxo_batch_done = await insert_utxos_in_batches(
api, keyring, config.utxo_batch_number, config.utxo_batch_size_per_shard, receiver_checkpoint, 250);
console.log(">>>> Complete %i big batch with %i UTXOs",
console.log(">>>> Complete %i big batch with %i UTXOs",
big_batch_idx + 1 , utxo_batch_done * config.utxo_batch_size_per_shard * manta_pay_config.shard_number);
}
console.log(">>>>>>>>> UTXO INSERT DONE >>>>>>>>");

console.log(">>>> Inserting void numbers: %i per batch, %i batch",
console.log(">>>> Inserting void numbers: %i per batch, %i batch",
config.vn_batch_size, config.vn_batch_number);
const vn_batch_done = await insert_void_numbers_in_batch(api, keyring, config.vn_batch_size, config.vn_batch_number, 0, 250);
console.log(">>>> Complete inserting %i void numbers", vn_batch_done * config.vn_batch_size);
Expand All @@ -227,7 +227,7 @@ export async function setup_storage(
* @param referendumIndexObject the index of the referendum that will be executed
*/
export async function execute_with_root_via_governance(
api: ApiPromise,
api: ApiPromise,
keyring: KeyringPair,
extrinsicData: any,
referendumIndexObject: any
Expand Down
1 change: 1 addition & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"correctness_test": "mocha -r ts-node/register rpc_correctness_test.ts",
"performance_test": "mocha -r ts-node/register rpc_performance_test.ts",
"runtime_upgrade_test": "mocha -r ts-node/register runtime_upgrade_test.ts",
"lint": "eslint ."
},
"keywords": [],
Expand Down
62 changes: 62 additions & 0 deletions tests/runtime_upgrade_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
import { manta_pay_types, rpc_api } from './types';
import {execute_with_root_via_governance } from './manta_pay';
import { delay } from './test-util';
import { assert } from 'chai';
import minimist, { ParsedArgs } from 'minimist';
import { blake2AsHex } from "@polkadot/util-crypto";
import * as fs from 'fs';

const test_config = {
ws_address: "ws://127.0.0.1:9800",
mnemonic: 'bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice',
timeout: 2000000
}

describe('Node RPC Test', () => {
it('Check RPC result', async () => {

let nodeAddress = "";
const args: ParsedArgs = minimist(process.argv.slice(2));
if (args["address"] == null) {
nodeAddress = test_config.ws_address;
} else {
nodeAddress = args["address"];
}
console.log("using address %s", nodeAddress);

const wsProvider = new WsProvider(nodeAddress);
const api = await ApiPromise.create({
provider: wsProvider,
types: manta_pay_types,
rpc: rpc_api});
const keyring = new Keyring({ type: 'sr25519' });
const aliceKeyPair = keyring.addFromMnemonic(test_config.mnemonic);

const oldRuntimeVersion = await api.rpc.state.getRuntimeVersion();
const oldSpecVersion = oldRuntimeVersion["specVersion"];

const code = fs.readFileSync('calamari.wasm').toString('hex');
let codeHash = blake2AsHex(`0x${code}`);
const authorizeUpgradeCallData = api.tx.parachainSystem.authorizeUpgrade(codeHash);
var referendumIndexObject = { referendumIndex: 0 };
execute_with_root_via_governance(api, aliceKeyPair, authorizeUpgradeCallData, referendumIndexObject);
await delay(60000);
api.tx.parachainSystem.enactAuthorizedUpgrade(`0x${code}`).signAndSend(aliceKeyPair, {nonce: -1});
Dengjianping marked this conversation as resolved.
Show resolved Hide resolved
await delay(120000);

let newRuntimeVersions = await api.rpc.state.getRuntimeVersion();
const newSpecVersion = newRuntimeVersions["specVersion"];
assert(newSpecVersion > oldSpecVersion);

let blockNow = await api.rpc.chain.getBlock();
let blockNumberNow = blockNow.block.header.number;
await delay(60000);
let blockLater = await api.rpc.chain.getBlock();
let blockNumberLater = blockLater.block.header.number;
assert(blockNumberLater > blockNumberNow);

api.disconnect();
}).timeout(test_config.timeout);
});