Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix contracts integration test #679

Merged
merged 4 commits into from
Oct 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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