From 76f2f3e6b11aa61c568fa2e922f4888bc490918e Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 31 Mar 2020 11:12:31 +0200 Subject: [PATCH 01/11] Use Charlies account for Solidity tests --- tests/consts.ts | 1 + tests/contracts-solidity.spec.ts | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/consts.ts b/tests/consts.ts index ac00daa..13b86ef 100644 --- a/tests/consts.ts +++ b/tests/consts.ts @@ -6,3 +6,4 @@ export const CREATION_FEE: BN = DOT.muln(200); export const GAS_REQUIRED = 5000000; export const ALICE = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"; export const BOB = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"; +export const CHARLIE = "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y"; \ No newline at end of file diff --git a/tests/contracts-solidity.spec.ts b/tests/contracts-solidity.spec.ts index b072241..aca8542 100644 --- a/tests/contracts-solidity.spec.ts +++ b/tests/contracts-solidity.spec.ts @@ -20,10 +20,8 @@ import { hexToBn, u8aToHex } from "@polkadot/util"; import { randomAsU8a } from "@polkadot/util-crypto"; import { KeyringPair } from "@polkadot/keyring/types"; import { Address } from "@polkadot/types/interfaces"; -import BN from "bn.js"; -import sha256 from "@chainsafe/as-sha256"; -import { ALICE as ALICE_ADDRESS, BOB as BOB_ADDRESS, CREATION_FEE, WSURL } from "./consts"; +import { CHARLIE as CHARLIE_ADDRESS, CREATION_FEE, WSURL } from "./consts"; import { callContract, instantiate, @@ -33,8 +31,7 @@ import { // This is a test account that is going to be created and funded before each test. const keyring = testKeyring({ type: "sr25519" }); -const ALICE = keyring.getPair(ALICE_ADDRESS); -const BOB = keyring.getPair(BOB_ADDRESS); +const BOB = keyring.getPair(CHARLIE); const randomSeed = randomAsU8a(32); let contractCreator: KeyringPair; let api: ApiPromise; From c4d9f5061561ec2fafa2655cf8aebd92f779c73d Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 31 Mar 2020 11:13:04 +0200 Subject: [PATCH 02/11] New ext_set_storage in Assemblyscript examples --- contracts/assemblyscript/erc20/assembly/env.ts | 3 ++- contracts/assemblyscript/erc20/assembly/lib.ts | 3 +-- contracts/assemblyscript/flipper/assembly/env.ts | 3 ++- contracts/assemblyscript/flipper/assembly/lib.ts | 8 ++++++-- contracts/assemblyscript/incrementer/assembly/env.ts | 3 ++- contracts/assemblyscript/incrementer/assembly/lib.ts | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/contracts/assemblyscript/erc20/assembly/env.ts b/contracts/assemblyscript/erc20/assembly/env.ts index 6173179..7fca770 100644 --- a/contracts/assemblyscript/erc20/assembly/env.ts +++ b/contracts/assemblyscript/erc20/assembly/env.ts @@ -7,11 +7,12 @@ export declare function ext_balance(): void; export declare function ext_caller(): void; +export declare function ext_clear_storage(key_ptr: i32): void; export declare function ext_get_storage(key_ptr: i32): i32; export declare function ext_println(str_ptr: i32, str_len: i32): void; export declare function ext_scratch_read(dest_ptr: i32, offset: i32, len: i32): void; export declare function ext_scratch_size(): i32; export declare function ext_scratch_write(src_ptr: i32, len: i32): void; export declare function ext_set_rent_allowance(value_ptr: i32, value_len: i32): void; -export declare function ext_set_storage(key_ptr: i32, value_non_null: i32, value_ptr: i32, value_len: i32): void; +export declare function ext_set_storage(key_ptr: i32, value_ptr: i32, value_len: i32): void; export declare function ext_value_transferred(): void; diff --git a/contracts/assemblyscript/erc20/assembly/lib.ts b/contracts/assemblyscript/erc20/assembly/lib.ts index ad7ff10..7f75ba6 100644 --- a/contracts/assemblyscript/erc20/assembly/lib.ts +++ b/contracts/assemblyscript/erc20/assembly/lib.ts @@ -46,9 +46,8 @@ export function setStorage(key: Uint8Array, value: Uint8Array | null): void { if(key.length === 32) { const pointer = value ? value!.dataStart : 0; const length = value ? value.length : 0; - const valueNonNull = i32(value !== null); - ext_set_storage(key.dataStart, valueNonNull, pointer, length); + ext_set_storage(key.dataStart, pointer, length); } } diff --git a/contracts/assemblyscript/flipper/assembly/env.ts b/contracts/assemblyscript/flipper/assembly/env.ts index bb8c1a9..34dc2d2 100644 --- a/contracts/assemblyscript/flipper/assembly/env.ts +++ b/contracts/assemblyscript/flipper/assembly/env.ts @@ -4,9 +4,10 @@ // If these functions are not used by our AssemblyScript module, they will not be included // in the compiled wat ans wasm files. +export declare function ext_clear_storage(key_ptr: i32): void; export declare function ext_get_storage(key_ptr: i32): i32; export declare function ext_scratch_read(dest_ptr: i32, offset: i32, len: i32): void; export declare function ext_scratch_size(): i32; export declare function ext_scratch_write(src_ptr: i32, len: i32): void; export declare function ext_set_rent_allowance(value_ptr: i32, value_len: i32): void; -export declare function ext_set_storage(key_ptr: i32, value_non_null: i32, value_ptr: i32, value_len: i32): void; +export declare function ext_set_storage(key_ptr: i32, value_ptr: i32, value_len: i32): void; diff --git a/contracts/assemblyscript/flipper/assembly/lib.ts b/contracts/assemblyscript/flipper/assembly/lib.ts index f7d1e05..363f86e 100644 --- a/contracts/assemblyscript/flipper/assembly/lib.ts +++ b/contracts/assemblyscript/flipper/assembly/lib.ts @@ -2,6 +2,7 @@ import { u128 } from "as-bignum"; import { + ext_clear_storage, ext_get_storage, ext_scratch_read, ext_scratch_size, @@ -26,12 +27,15 @@ export function toBytes(num: T, le: boolean = true): Uint8Array { assert(false); } +export function clearStorage(key: Uint8Array): void { + ext_clear_storage(key.dataStart); +} + export function setStorage(key: Uint8Array, value: Uint8Array | null): void { const pointer = value ? value!.dataStart : 0; const length = value ? value.length : 0; - const valueNonNull = i32(value !== null); - ext_set_storage(key.dataStart, valueNonNull, pointer, length); + ext_set_storage(key.dataStart, pointer, length); } // check for length 32 bytes diff --git a/contracts/assemblyscript/incrementer/assembly/env.ts b/contracts/assemblyscript/incrementer/assembly/env.ts index 68a20d2..6f40a79 100644 --- a/contracts/assemblyscript/incrementer/assembly/env.ts +++ b/contracts/assemblyscript/incrementer/assembly/env.ts @@ -4,9 +4,10 @@ // If these functions are not used by our AssemblyScript module, they will not be included // in the compiled wat ans wasm files. +export declare function ext_clear_storage(key_ptr: i32): void; export declare function ext_get_storage(key_ptr: i32): i32; export declare function ext_scratch_read(dest_ptr: i32, offset: i32, len: i32): void; export declare function ext_scratch_size(): i32; export declare function ext_scratch_write(src_ptr: i32, len: i32): void; export declare function ext_set_rent_allowance(value_ptr: i32, value_len: i32): void; -export declare function ext_set_storage(key_ptr: i32, value_non_null: i32, value_ptr: i32, value_len: i32): void; +export declare function ext_set_storage(key_ptr: i32, value_ptr: i32, value_len: i32): void; diff --git a/contracts/assemblyscript/incrementer/assembly/lib.ts b/contracts/assemblyscript/incrementer/assembly/lib.ts index d12438d..0ee2359 100644 --- a/contracts/assemblyscript/incrementer/assembly/lib.ts +++ b/contracts/assemblyscript/incrementer/assembly/lib.ts @@ -31,7 +31,7 @@ export function setStorage(key: Uint8Array, value: Uint8Array | null): void { const length = value ? value.length : 0; const valueNonNull = i32(value !== null); - ext_set_storage(key.dataStart, valueNonNull, pointer, length); + ext_set_storage(key.dataStart, pointer, length); } // check for length 32 bytes From 3daf2b15462caa35addfe706275ae8f7beee6751 Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 31 Mar 2020 11:41:25 +0200 Subject: [PATCH 03/11] Fix raw Rust examples --- contracts/rust/raw-incrementer/src/ext.rs | 9 +++------ contracts/rust/restore-contract/src/ext.rs | 10 ++++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/contracts/rust/raw-incrementer/src/ext.rs b/contracts/rust/raw-incrementer/src/ext.rs index fc038f2..103893d 100644 --- a/contracts/rust/raw-incrementer/src/ext.rs +++ b/contracts/rust/raw-incrementer/src/ext.rs @@ -19,7 +19,7 @@ use codec::Encode; mod cabi { extern "C" { - pub fn ext_set_storage(key_ptr: u32, value_non_null: u32, value_ptr: u32, value_len: u32); + pub fn ext_set_storage(key_ptr: u32, value_ptr: u32, value_len: u32); pub fn ext_get_storage(key_ptr: u32) -> u32; pub fn ext_scratch_size() -> u32; pub fn ext_scratch_read(dest_ptr: u32, offset: u32, len: u32); @@ -35,15 +35,12 @@ pub fn set_storage(key: &Key, value: Option<&[u8]>) { unsafe { let mut value_ptr = 0; let mut value_len = 0; - let value_non_null = if let Some(v) = value { + if let Some(v) = value { value_ptr = v.as_ptr() as u32; value_len = v.len() as u32; - 1 - } else { - 0 }; - cabi::ext_set_storage(key.0.as_ptr() as u32, value_non_null, value_ptr, value_len); + cabi::ext_set_storage(key.0.as_ptr() as u32, value_ptr, value_len); } } diff --git a/contracts/rust/restore-contract/src/ext.rs b/contracts/rust/restore-contract/src/ext.rs index c3b6a77..39f560a 100644 --- a/contracts/rust/restore-contract/src/ext.rs +++ b/contracts/rust/restore-contract/src/ext.rs @@ -19,7 +19,7 @@ use codec::{Encode, Decode}; mod cabi { extern "C" { - pub fn ext_set_storage(key_ptr: u32, value_non_null: u32, value_ptr: u32, value_len: u32); + pub fn ext_set_storage(key_ptr: u32, value_ptr: u32, value_len: u32); pub fn ext_restore_to( dest_ptr: u32, dest_len: u32, @@ -48,15 +48,13 @@ pub fn set_storage(key: &Key, value: Option<&[u8]>) { unsafe { let mut value_ptr = 0; let mut value_len = 0; - let value_non_null = if let Some(v) = value { + if let Some(v) = value { value_ptr = v.as_ptr() as u32; value_len = v.len() as u32; - 1 - } else { - 0 }; - cabi::ext_set_storage(key.as_ptr() as u32, value_non_null, value_ptr, value_len); + + cabi::ext_set_storage(key.as_ptr() as u32, value_ptr, value_len); } } From 6e49b57e4d00467fe8bb762424340d1f911fda9f Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 31 Mar 2020 11:41:44 +0200 Subject: [PATCH 04/11] Use Charlie for Solang tests --- tests/contracts-solidity.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/contracts-solidity.spec.ts b/tests/contracts-solidity.spec.ts index aca8542..7d3e4f8 100644 --- a/tests/contracts-solidity.spec.ts +++ b/tests/contracts-solidity.spec.ts @@ -31,7 +31,7 @@ import { // This is a test account that is going to be created and funded before each test. const keyring = testKeyring({ type: "sr25519" }); -const BOB = keyring.getPair(CHARLIE); +const BOB = keyring.getPair(CHARLIE_ADDRESS); const randomSeed = randomAsU8a(32); let contractCreator: KeyringPair; let api: ApiPromise; @@ -59,7 +59,7 @@ beforeEach( } ); -describe("AssemblyScript Smart Contracts", () => { +describe("Solang Smart Contracts", () => { test("Raw Flipper contract", async (done): Promise => { // See https://github.com/paritytech/pallet-contracts-waterfall/issues/6 for info about // how to get the STORAGE_KEY of an instantiated contract From 8a3ab744373c4bc03bce38648638fa42e6441b9a Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 31 Mar 2020 11:42:01 +0200 Subject: [PATCH 05/11] Update ink submodule version --- lib/ink | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ink b/lib/ink index 9dd4f47..46b2823 160000 --- a/lib/ink +++ b/lib/ink @@ -1 +1 @@ -Subproject commit 9dd4f47d3a1f156af3ffa2d923aab489fe868a95 +Subproject commit 46b2823413b71818ed4536c4c3e63b7e9bbc70ce From 81e16ca2f22926719fc2d0971096cd822d1c610b Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 31 Mar 2020 11:56:01 +0200 Subject: [PATCH 06/11] Remove unused ext_clear_storage from AS examples --- contracts/assemblyscript/erc20/assembly/env.ts | 1 - contracts/assemblyscript/flipper/assembly/env.ts | 1 - contracts/assemblyscript/flipper/assembly/lib.ts | 5 ----- contracts/assemblyscript/incrementer/assembly/env.ts | 1 - 4 files changed, 8 deletions(-) diff --git a/contracts/assemblyscript/erc20/assembly/env.ts b/contracts/assemblyscript/erc20/assembly/env.ts index 7fca770..15b51d9 100644 --- a/contracts/assemblyscript/erc20/assembly/env.ts +++ b/contracts/assemblyscript/erc20/assembly/env.ts @@ -7,7 +7,6 @@ export declare function ext_balance(): void; export declare function ext_caller(): void; -export declare function ext_clear_storage(key_ptr: i32): void; export declare function ext_get_storage(key_ptr: i32): i32; export declare function ext_println(str_ptr: i32, str_len: i32): void; export declare function ext_scratch_read(dest_ptr: i32, offset: i32, len: i32): void; diff --git a/contracts/assemblyscript/flipper/assembly/env.ts b/contracts/assemblyscript/flipper/assembly/env.ts index 34dc2d2..fdfdcb9 100644 --- a/contracts/assemblyscript/flipper/assembly/env.ts +++ b/contracts/assemblyscript/flipper/assembly/env.ts @@ -4,7 +4,6 @@ // If these functions are not used by our AssemblyScript module, they will not be included // in the compiled wat ans wasm files. -export declare function ext_clear_storage(key_ptr: i32): void; export declare function ext_get_storage(key_ptr: i32): i32; export declare function ext_scratch_read(dest_ptr: i32, offset: i32, len: i32): void; export declare function ext_scratch_size(): i32; diff --git a/contracts/assemblyscript/flipper/assembly/lib.ts b/contracts/assemblyscript/flipper/assembly/lib.ts index 363f86e..03bc737 100644 --- a/contracts/assemblyscript/flipper/assembly/lib.ts +++ b/contracts/assemblyscript/flipper/assembly/lib.ts @@ -2,7 +2,6 @@ import { u128 } from "as-bignum"; import { - ext_clear_storage, ext_get_storage, ext_scratch_read, ext_scratch_size, @@ -27,10 +26,6 @@ export function toBytes(num: T, le: boolean = true): Uint8Array { assert(false); } -export function clearStorage(key: Uint8Array): void { - ext_clear_storage(key.dataStart); -} - export function setStorage(key: Uint8Array, value: Uint8Array | null): void { const pointer = value ? value!.dataStart : 0; const length = value ? value.length : 0; diff --git a/contracts/assemblyscript/incrementer/assembly/env.ts b/contracts/assemblyscript/incrementer/assembly/env.ts index 6f40a79..a690eb9 100644 --- a/contracts/assemblyscript/incrementer/assembly/env.ts +++ b/contracts/assemblyscript/incrementer/assembly/env.ts @@ -4,7 +4,6 @@ // If these functions are not used by our AssemblyScript module, they will not be included // in the compiled wat ans wasm files. -export declare function ext_clear_storage(key_ptr: i32): void; export declare function ext_get_storage(key_ptr: i32): i32; export declare function ext_scratch_read(dest_ptr: i32, offset: i32, len: i32): void; export declare function ext_scratch_size(): i32; From 261280fafa0cd22492c5d3b1465334808ead9e12 Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 31 Mar 2020 12:05:49 +0200 Subject: [PATCH 07/11] fix build.sh path mix-up --- build.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index ea74337..099c9e1 100755 --- a/build.sh +++ b/build.sh @@ -16,10 +16,9 @@ if which podman || docker info; then cd -; else echo "Please install and run Docker or Podman if you want to compile the Solang contracts and succesfully run their tests."; fi - -cd lib + git submodule foreach git pull origin master -cd ink/examples/flipper +cd lib/ink/examples/flipper cargo +nightly contract build cargo +nightly contract generate-metadata cd - From 271f43baec4101e3e279bdc8097ce411aeb9f207 Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 31 Mar 2020 12:33:02 +0200 Subject: [PATCH 08/11] change docker conditional for CI --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 099c9e1..3456662 100755 --- a/build.sh +++ b/build.sh @@ -8,7 +8,7 @@ set -ev provide-parity-tools -if which podman || docker info; then +if which podman || which docker; then provide-wabt provide-solang cd contracts/solidity/flipper From 9ce9c3ec4c5e7574ddd6ac1cd7ed57dbf1c0f8ab Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 31 Mar 2020 13:32:41 +0200 Subject: [PATCH 09/11] add check for CI environment --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 3456662..a256f76 100755 --- a/build.sh +++ b/build.sh @@ -8,7 +8,7 @@ set -ev provide-parity-tools -if which podman || which docker; then +if which podman || which docker || $CI_JOB_ID; then provide-wabt provide-solang cd contracts/solidity/flipper From 944a741e17ad851744951d6e194340031239db95 Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 31 Mar 2020 13:36:07 +0200 Subject: [PATCH 10/11] BOB -> CHARLIE --- tests/contracts-solidity.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/contracts-solidity.spec.ts b/tests/contracts-solidity.spec.ts index 7d3e4f8..179f6b8 100644 --- a/tests/contracts-solidity.spec.ts +++ b/tests/contracts-solidity.spec.ts @@ -31,7 +31,7 @@ import { // This is a test account that is going to be created and funded before each test. const keyring = testKeyring({ type: "sr25519" }); -const BOB = keyring.getPair(CHARLIE_ADDRESS); +const CHARLIE = keyring.getPair(CHARLIE_ADDRESS); const randomSeed = randomAsU8a(32); let contractCreator: KeyringPair; let api: ApiPromise; @@ -47,7 +47,7 @@ beforeEach( return api.tx.balances .transfer(contractCreator.address, CREATION_FEE.muln(5)) - .signAndSend(BOB, (result: SubmittableResult): void => { + .signAndSend(CHARLIE, (result: SubmittableResult): void => { if ( result.status.isInBlock && result.findRecord("system", "ExtrinsicSuccess") From 996fb871d578382fb3709c1b0d27439b13842a2c Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 31 Mar 2020 14:00:56 +0200 Subject: [PATCH 11/11] add check for CI environment --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index a256f76..d69b19a 100755 --- a/build.sh +++ b/build.sh @@ -8,7 +8,7 @@ set -ev provide-parity-tools -if which podman || which docker || $CI_JOB_ID; then +if which podman || which docker || [ -n "$CI_JOB_ID" ]; then provide-wabt provide-solang cd contracts/solidity/flipper