From 9806b1fa8dbdda54c651e2cac9746cb49090b9fc Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 3 Oct 2022 11:45:53 +0100 Subject: [PATCH 1/4] Fix contracts integration test --- testing/integration-tests/src/frame/contracts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/integration-tests/src/frame/contracts.rs b/testing/integration-tests/src/frame/contracts.rs index e0fdbe7b50..3906d5fa70 100644 --- a/testing/integration-tests/src/frame/contracts.rs +++ b/testing/integration-tests/src/frame/contracts.rs @@ -61,7 +61,7 @@ impl ContractsTestContext { 100_000_000_000_000_000, // endowment Weight { ref_time: 500_000_000_000, - proof_size: 0, + proof_size: u64::MAX, }, // gas_limit None, // storage_deposit_limit code, @@ -106,7 +106,7 @@ impl ContractsTestContext { 100_000_000_000_000_000, // endowment Weight { ref_time: 500_000_000_000, - proof_size: 0, + proof_size: u64::MAX, }, // gas_limit None, // storage_deposit_limit code_hash, From baad66b5ea16b1deb0c999f73f2d43bc5e9b1eb7 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 3 Oct 2022 15:33:20 +0100 Subject: [PATCH 2/4] Revert proof size to 0 --- testing/integration-tests/src/frame/contracts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/integration-tests/src/frame/contracts.rs b/testing/integration-tests/src/frame/contracts.rs index 3906d5fa70..e0fdbe7b50 100644 --- a/testing/integration-tests/src/frame/contracts.rs +++ b/testing/integration-tests/src/frame/contracts.rs @@ -61,7 +61,7 @@ impl ContractsTestContext { 100_000_000_000_000_000, // endowment Weight { ref_time: 500_000_000_000, - proof_size: u64::MAX, + proof_size: 0, }, // gas_limit None, // storage_deposit_limit code, @@ -106,7 +106,7 @@ impl ContractsTestContext { 100_000_000_000_000_000, // endowment Weight { ref_time: 500_000_000_000, - proof_size: u64::MAX, + proof_size: 0, }, // gas_limit None, // storage_deposit_limit code_hash, From 33e665b79ba30914e1a66bdcb104c5ad4c6e5e6f Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 3 Oct 2022 15:46:31 +0100 Subject: [PATCH 3/4] Upload code for instantiate test --- .../integration-tests/src/frame/contracts.rs | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/testing/integration-tests/src/frame/contracts.rs b/testing/integration-tests/src/frame/contracts.rs index e0fdbe7b50..25f554c08b 100644 --- a/testing/integration-tests/src/frame/contracts.rs +++ b/testing/integration-tests/src/frame/contracts.rs @@ -35,6 +35,13 @@ struct ContractsTestContext { type Hash = ::Hash; type AccountId = ::AccountId; +const CONTRACT: &str = r#" + (module + (func (export "call")) + (func (export "deploy")) + ) +"#; + impl ContractsTestContext { async fn init() -> Self { let cxt = test_context().await; @@ -47,14 +54,27 @@ impl ContractsTestContext { self.cxt.client() } + async fn upload_code(&self) -> Result { + let code = wabt::wat2wasm(CONTRACT).expect("invalid wabt"); + + let upload_tx = node_runtime::tx().contracts().upload_code(code, None); + + let events = self + .client() + .tx() + .sign_and_submit_then_watch_default(&upload_tx, &self.signer) + .await? + .wait_for_finalized_success() + .await?; + + let code_stored = events + .find_first::()? + .ok_or_else(|| Error::Other("Failed to find a CodeStored event".into()))?; + Ok(code_stored.code_hash) + } + async fn instantiate_with_code(&self) -> Result<(Hash, AccountId), Error> { tracing::info!("instantiate_with_code:"); - const CONTRACT: &str = r#" - (module - (func (export "call")) - (func (export "deploy")) - ) - "#; let code = wabt::wat2wasm(CONTRACT).expect("invalid wabt"); let instantiate_tx = node_runtime::tx().contracts().instantiate_with_code( @@ -173,9 +193,9 @@ async fn tx_instantiate_with_code() { #[tokio::test] async fn tx_instantiate() { let ctx = ContractsTestContext::init().await; - let (code_hash, _) = ctx.instantiate_with_code().await.unwrap(); + let code_hash = ctx.upload_code().await.unwrap(); - let instantiated = ctx.instantiate(code_hash, vec![], vec![1u8]).await; + let instantiated = ctx.instantiate(code_hash, vec![], vec![]).await; assert!( instantiated.is_ok(), From 11e189239ddbce2017400ba36b5f2c192896f562 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 3 Oct 2022 17:43:44 +0100 Subject: [PATCH 4/4] Set proof size to half of max --- testing/integration-tests/src/frame/contracts.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/testing/integration-tests/src/frame/contracts.rs b/testing/integration-tests/src/frame/contracts.rs index 25f554c08b..6376409004 100644 --- a/testing/integration-tests/src/frame/contracts.rs +++ b/testing/integration-tests/src/frame/contracts.rs @@ -42,6 +42,8 @@ const CONTRACT: &str = r#" ) "#; +const PROOF_SIZE: u64 = u64::MAX / 2; + impl ContractsTestContext { async fn init() -> Self { let cxt = test_context().await; @@ -81,7 +83,7 @@ impl ContractsTestContext { 100_000_000_000_000_000, // endowment Weight { ref_time: 500_000_000_000, - proof_size: 0, + proof_size: PROOF_SIZE, }, // gas_limit None, // storage_deposit_limit code, @@ -126,7 +128,7 @@ impl ContractsTestContext { 100_000_000_000_000_000, // endowment Weight { ref_time: 500_000_000_000, - proof_size: 0, + proof_size: PROOF_SIZE, }, // gas_limit None, // storage_deposit_limit code_hash, @@ -161,7 +163,7 @@ impl ContractsTestContext { 0, // value Weight { ref_time: 500_000_000, - proof_size: 0, + proof_size: PROOF_SIZE, }, // gas_limit None, // storage_deposit_limit input_data,