diff --git a/contracts/marketplace/Cargo.toml b/contracts/marketplace/Cargo.toml index 6674601..3f81404 100644 --- a/contracts/marketplace/Cargo.toml +++ b/contracts/marketplace/Cargo.toml @@ -11,6 +11,9 @@ scale-info = { version = "2.3", default-features = false, features = ["derive"], openbrush = { tag = "3.0.0", git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false, features = ["ownable", "psp34", "reentrancy_guard"] } pallet_marketplace = { path = "../../logics", default-features = false } +[dev-dependencies] +ink_e2e = "4.0.1" + [lib] path = "lib.rs" @@ -24,6 +27,7 @@ std = [ "pallet_marketplace/std", ] ink-as-dependency = [] +e2e-tests = [] [profile.dev] overflow-checks = false diff --git a/contracts/marketplace/lib.rs b/contracts/marketplace/lib.rs index 73d6ef1..46c6f02 100644 --- a/contracts/marketplace/lib.rs +++ b/contracts/marketplace/lib.rs @@ -331,4 +331,47 @@ pub mod marketplace { AccountId::from([0x2; 32]) } } + + /// end-to-end (E2E) or integration tests for marketplace. + /// + /// When running these you need to make sure that you: + /// - Compile the tests with the `e2e-tests` feature flag enabled (`--features e2e-tests`) + /// - Are running a Substrate node which contains `pallet-contracts` in the background + #[cfg(all(test, feature = "e2e-tests"))] + mod e2e_tests { + /// Imports all the definitions from the outer scope so we can use them here. + use super::*; + + /// A helper function used for calling contract messages. + use ink_e2e::build_message; + + /// The End-to-End test `Result` type. + type E2EResult = std::result::Result>; + + /// We test that we can upload and instantiate the contract using its default constructor. + #[ink_e2e::test] + async fn init_works(mut client: ink_e2e::Client) -> E2EResult<()> { + // Given + let constructor = MarketplaceRef::new(fee_recipient()); + + // When + let contract_account_id = client + .instantiate("marketplace", &ink_e2e::alice(), constructor, 0, None) + .await + .expect("instantiate failed") + .account_id; + + // Then + let marketplace_fee = build_message::(contract_account_id.clone()) + .call(|marketplace| marketplace.get_marketplace_fee()); + let marketplace_fee_result = client.call_dry_run(&ink_e2e::alice(), &owner, 0, None).await; + assert!(matches!(marketplace_fee_result.return_value(), 100)); + + Ok(()) + } + + fn fee_recipient() -> AccountId { + AccountId::from([0x1; 32]) + } + } } diff --git a/contracts/psp34/Cargo.toml b/contracts/psp34/Cargo.toml index abdfd3d..f1ab7d0 100644 --- a/contracts/psp34/Cargo.toml +++ b/contracts/psp34/Cargo.toml @@ -23,4 +23,4 @@ std = [ "openbrush/std", ] -ink-as-dependency = [] \ No newline at end of file +ink-as-dependency = [] diff --git a/contracts/rmrk/Cargo.toml b/contracts/rmrk/Cargo.toml index 259be1b..41304e0 100644 --- a/contracts/rmrk/Cargo.toml +++ b/contracts/rmrk/Cargo.toml @@ -29,4 +29,4 @@ std = [ "rmrk/std", ] -ink-as-dependency = [] \ No newline at end of file +ink-as-dependency = []