Skip to content

Commit

Permalink
Fix runtime upgrade test by using governance instead of SUDO (#924)
Browse files Browse the repository at this point in the history
* Migrate runtime-upgrade test to mocha

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Bump spec-version for test

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Add trigger

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* use wget properlt to download last release binary

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Fix missing config-for-runtime-upgrade-test

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Fix directory

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* CLean up

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Fix test

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Get rid of testnet-ci chain-specs

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Use object for referendumIndex

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Use object for referendumIndex

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Use object for referendumIndex

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Clean up

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Clean up

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Check

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Check

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Check

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Check

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Check

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Check

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Check

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Fix runtime upgrade code

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Clean up

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Clean up

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Clean up

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Update all ci workflows

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Update all ci workflows

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Increase wait time

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Bump timeout

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Bump timeout

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Switch to -local

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Upload 9921 log

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Update runtime-upgrade resource

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Remove unused code

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Check block production in mocha test

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* Revert spec_version bumps that were for testing only

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>

* fix duplicate line

Signed-off-by: Charles Ferrell <charlie@manta.network>

Signed-off-by: Georgi Zlatarev <georgi.zlatarev@manta.network>
Signed-off-by: Charles Ferrell <charlie@manta.network>
Co-authored-by: Charles Ferrell <charlie@manta.network>
Co-authored-by: Adam Reif <garandor@manta.network>
Signed-off-by: Charles Ferrell <charlie@manta.network>
  • Loading branch information
3 people committed Dec 27, 2022
1 parent d55dad6 commit 6afddf2
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 525 deletions.
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});
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);
});

0 comments on commit 6afddf2

Please sign in to comment.