Skip to content

Commit

Permalink
Fix contracts integration test (#679)
Browse files Browse the repository at this point in the history
* Fix contracts integration test

* Revert proof size to 0

* Upload code for instantiate test

* Set proof size to half of max
  • Loading branch information
ascjones committed Oct 3, 2022
1 parent d4fda93 commit 432df58
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions testing/integration-tests/src/frame/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ struct ContractsTestContext {
type Hash = <SubstrateConfig as Config>::Hash;
type AccountId = <SubstrateConfig as Config>::AccountId;

const CONTRACT: &str = r#"
(module
(func (export "call"))
(func (export "deploy"))
)
"#;

const PROOF_SIZE: u64 = u64::MAX / 2;

impl ContractsTestContext {
async fn init() -> Self {
let cxt = test_context().await;
Expand All @@ -47,21 +56,34 @@ impl ContractsTestContext {
self.cxt.client()
}

async fn upload_code(&self) -> Result<Hash, Error> {
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::<events::CodeStored>()?
.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(
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,
Expand Down Expand Up @@ -106,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,
Expand Down Expand Up @@ -141,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,
Expand Down Expand Up @@ -173,9 +195,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(),
Expand Down

0 comments on commit 432df58

Please sign in to comment.