소스 검색

network-tests: fix call to setCode in runtime upgrade

Mokhtar Naamani 4 년 전
부모
커밋
3e92c16b11
2개의 변경된 파일32개의 추가작업 그리고 18개의 파일을 삭제
  1. 23 13
      tests/network-tests/run-tests.sh
  2. 9 5
      utils/api-examples/src/dev-set-runtime-code.ts

+ 23 - 13
tests/network-tests/run-tests.sh

@@ -10,6 +10,11 @@ DATA_PATH=${DATA_PATH:=~/tmp}
 # Alice is the source of funds for all new accounts that are created in the tests.
 ALICE_INITIAL_BALANCE=${ALICE_INITIAL_BALANCE:=100000000}
 
+# The docker image tag to use for joystream/node as the starting chain
+# that will be upgraded to the latest runtime.
+CURRENT_RUNTIME=alexandria
+TARGET_RUNTIME=babylon
+
 mkdir -p ${DATA_PATH}
 
 echo "{
@@ -32,7 +37,7 @@ echo '
 ' > ${DATA_PATH}/initial-members.json
 
 # Create a chain spec file
-docker run --rm -v ${DATA_PATH}:/data --entrypoint ./chain-spec-builder joystream/node:alexandria \
+docker run --rm -v ${DATA_PATH}:/data --entrypoint ./chain-spec-builder joystream/node:${CURRENT_RUNTIME} \
   new \
   --authority-seeds Alice \
   --sudo-account  5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY \
@@ -42,13 +47,14 @@ docker run --rm -v ${DATA_PATH}:/data --entrypoint ./chain-spec-builder joystrea
   --initial-members-path /data/initial-members.json
 
 # Convert the chain spec file to a raw chainspec file
-docker run --rm -v ${DATA_PATH}:/data joystream/node:alexandria build-spec \
+docker run --rm -v ${DATA_PATH}:/data joystream/node:${CURRENT_RUNTIME} build-spec \
   --raw --disable-default-bootnode \
   --chain /data/chain-spec.json > ~/tmp/chain-spec-raw.json
 
-# Start an Alexandria chain with generated chain spec
-CONTAINER_ID=`docker run -d -v ${DATA_PATH}:/data -p 9944:9944 joystream/node:alexandria \
-  --validator --alice --unsafe-ws-external --rpc-cors=all --log runtime \
+# Start a chain with generated chain spec
+# Add "-l ws=trace,ws::handler=info" to get websocket trace logs
+CONTAINER_ID=`docker run -d -v ${DATA_PATH}:/data -p 9944:9944 joystream/node:${CURRENT_RUNTIME} \
+  --validator --alice --unsafe-ws-external --rpc-cors=all -l runtime \
   --chain /data/chain-spec-raw.json`
 
 function cleanup() {
@@ -59,19 +65,23 @@ function cleanup() {
 
 trap cleanup EXIT
 
-# Display current runtime version
-yarn workspace api-examples tsnode-strict src/status.ts
-
 # Copy new runtime wasm file from target joystream/node image
-id=$(docker create joystream/node)
+echo "Extracting wasm blob from target joystream/node image."
+id=$(docker create joystream/node:${TARGET_RUNTIME})
 docker cp $id:/joystream/runtime.compact.wasm .tmp/
 docker rm $id
 
-echo "Performing runtime upgrade."
-DEBUG=* yarn workspace api-examples tsnode-strict \
-  src/dev-set-runtime-code.ts -- `pwd`/.tmp/runtime.compact.wasm
+# Should we clone master branch to run scripts from to use correct types for live network?
+# New types seems to work for our needs though, no warnings about missing types
+# or anything like that..
 
-sleep 6
+# Display current runtime version
+yarn workspace api-examples tsnode-strict src/status.ts
+
+echo "Performing runtime upgrade."
+# DEBUG=* yarn workspace api-examples tsnode-strict \
+#   src/dev-set-runtime-code.ts -- `pwd`/.tmp/runtime.compact.wasm
+DEBUG=* yarn workspace api-examples dev-set-runtime-code `pwd`/.tmp/runtime.compact.wasm
 
 # Display runtime version
 yarn workspace api-examples tsnode-strict src/status.ts

+ 9 - 5
utils/api-examples/src/dev-set-runtime-code.ts

@@ -3,8 +3,10 @@ import { types } from '@joystream/types'
 import { Keyring } from '@polkadot/keyring'
 import { ISubmittableResult } from '@polkadot/types/types/'
 import { DispatchError, DispatchResult } from '@polkadot/types/interfaces/system'
-import { TypeRegistry } from '@polkadot/types'
+import { TypeRegistry, Bytes } from '@polkadot/types'
 import fs from 'fs'
+import Call from '@polkadot/types/generic/Call'
+import { compactAddLength } from '@polkadot/util'
 
 function onApiDisconnected() {
   process.exit(2)
@@ -22,9 +24,8 @@ async function main() {
     process.exit(1)
   }
 
-  // const wasm = '0x' + fs.readFileSync(file).toString('hex')
-  const wasm = fs.readFileSync(file)
-  console.log('WASM file size:', wasm.byteLength)
+  const wasm = Uint8Array.from(fs.readFileSync(file))
+  console.log('WASM bytes:', wasm.byteLength)
 
   const provider = new WsProvider('ws://127.0.0.1:9944')
 
@@ -59,10 +60,13 @@ async function main() {
   // DO SET UNCHECKED!
   // const tx = api.tx.system.setCodeWithoutChecks(wasm)
 
-  const setCodeTx = api.tx.system.setCode(wasm)
+  const setCodeTx = api.tx.system.setCode(compactAddLength(wasm))
 
   const sudoTx = api.tx.sudo.sudoUncheckedWeight(setCodeTx, 1)
   const signedTx = sudoTx.sign(sudo, { nonce })
+  console.log('Tx size:', signedTx.length)
+  const wasmCodeInTxArg = (signedTx.method.args[0] as Call).args[0]
+  console.log('WASM code arg byte length:', (wasmCodeInTxArg as Bytes).byteLength)
 
   signedTx.send((result: ISubmittableResult) => {
     if (result.status.isInBlock && result.events !== undefined) {