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

added e2e test #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
46 changes: 45 additions & 1 deletion lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// and we need to use `no_std` and `no_main` attributes
// to compile the contract as a Wasm binary.
// If `std` feature is enabled, we are building for native target
// and we don't need these attributes.
// and we don't need these attributes.
// ink! builds in `std` mode when running tests.
//
// `no_std` attribute disables the standard library.
Expand Down Expand Up @@ -183,4 +183,48 @@ mod cross_contract_flipper {
todo!()
}
}

#[cfg(all(test, feature = "e2e-tests"))]
mod e2e_tests {
use super::*;
use ink_e2e::ContractsBackend;

type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[ink_e2e::test]
async fn it_works<Client: ContractsBackend>(mut client: Client) -> E2EResult<()> {
let mut constructor = OtherContractRef::new(true);
let _contract = client
.instantiate("other_contract", &ink_e2e::alice(), &mut constructor)
.submit()
.await
.expect("instantiate failed");

let code_hash = client
.upload("other_contract", &ink_e2e::alice())
.submit()
.await
.expect("upload failed")
.code_hash;

let mut constructor = CrossContractFlipperRef::new(code_hash);
let cross_contract = client
.instantiate(
"cross_contract_flipper",
&ink_e2e::alice(),
&mut constructor,
)
.submit()
.await
.expect("instantiate failed");

let mut call_builder = cross_contract.call_builder::<CrossContractFlipper>();

let get = call_builder.call_get();
let get_res = client.call(&ink_e2e::bob(), &get).dry_run().await?;
assert!(matches!(get_res.return_value(), true));

Ok(())
}
}
}