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

[E2E] Add create_call_builder for testing on-chain contracts #2075

Merged
merged 26 commits into from
Jan 29, 2024

Conversation

cmichi
Copy link
Collaborator

@cmichi cmichi commented Jan 25, 2024

Why?

Allows for easy writing of an E2E test that runs against an already deployed contract. Our typical examples always have the whole instantiation workflow with creating a contract instance, constructor & co.

So you can e.g. take a snapshot of Aleph Zero, upgrade your contract there to a new ink! version, and then run your E2E test suite against this updated contract to assert that everything will still work.

Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can make a simple free function which constructs from an account id, extracting this code here

<<Contract as ContractCallBuilder>::Type as FromAccountId<E>>::from_account_id(
    self.account_id.clone(),
)

https://github.com/paritytech/ink/blob/cmichi-reexport-contractcallbuilder/crates/e2e/src/contract_results.rs#L52

To replace

    type CallBuilderType = <Flipper as ink_e2e::ContractCallBuilder>::Type;
    let call_builder = CallBuilderType {
        account_id: acc_id
    };

with e.g.

let call_builder = create_call_builder::<Flipper>(acc_id);

Copy link

github-actions bot commented Jan 25, 2024

🦑 📈 ink! Example Contracts ‒ Changes Report 📉 🦑

These are the results when building the integration-tests/* contracts from this branch with cargo-contract and comparing them to ink! master:

Contract Upstream Size (kB) PR Size (kB) Diff (kB) Diff (%) Change
basic-contract-caller 3.303 3.303 0 0
basic-contract-caller/other-contract 1.583 1.583 0 0
call-builder-return-value 9.169 9.169 0 0
call-runtime 2.061 2.061 0 0
conditional-compilation 1.49 1.49 0 0
contract-storage 7.568 7.568 0 0
contract-terminate 1.329 1.329 0 0
contract-transfer 1.689 1.689 0 0
custom-allocator 7.692 7.692 0 0
dns 7.318 7.318 0 0
e2e-call-runtime 1.296 1.296 0 0
e2e-runtime-only-backend 1.881 1.881 0 0
erc1155 14.237 14.237 0 0
erc20 6.918 6.918 0 0
erc721 9.873 9.873 0 0
events 5.258 5.258 0 0
flipper 1.639 1.639 0 0
incrementer 1.504 1.504 0 0
lang-err-integration-tests/call-builder-delegate 2.638 2.638 0 0
lang-err-integration-tests/call-builder 5.066 5.066 0 0
lang-err-integration-tests/constructors-return-value 1.985 1.985 0 0
lang-err-integration-tests/contract-ref 4.629 4.629 0 0
lang-err-integration-tests/integration-flipper 1.815 1.815 0 0
lazyvec-integration-test 4.616 4.616 0 0
mapping-integration-tests 7.999 7.999 0 0
mother 12.741 12.741 0 0
multi-contract-caller 6.106 6.106 0 0
multi-contract-caller/accumulator 1.378 1.378 0 0
multi-contract-caller/adder 1.968 1.968 0 0
multi-contract-caller/subber 1.988 1.988 0 0
multisig 21.688 21.688 0 0
payment-channel 5.659 5.659 0 0
sr25519-verification 1.142 1.142 0 0
static-buffer 1.654 1.654 0 0
trait-dyn-cross-contract-calls 2.793 2.793 0 0
trait-dyn-cross-contract-calls/contracts/incrementer 1.545 1.545 0 0
trait-erc20 7.294 7.294 0 0
trait-flipper 1.49 1.49 0 0
trait-incrementer 1.614 1.614 0 0
upgradeable-contracts/delegator 3.151 3.151 0 0
upgradeable-contracts/delegator/delegatee 1.609 1.609 0 0
upgradeable-contracts/set-code-hash 1.743 1.743 0 0
upgradeable-contracts/set-code-hash/updated-incrementer 1.721 1.721 0 0
wildcard-selector 2.846 2.846 0 0

Link to the run | Last update: Mon Jan 29 15:13:30 CET 2024

@cmichi cmichi changed the title Reexport ContractCallBuilder from ink_e2e [E2E] Add create_call_builder for testing on-chain contracts Jan 26, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8b5b497) 53.70% compared to head (337d298) 53.72%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2075      +/-   ##
==========================================
+ Coverage   53.70%   53.72%   +0.01%     
==========================================
  Files         223      223              
  Lines        7040     7040              
  Branches     3141     3120      -21     
==========================================
+ Hits         3781     3782       +1     
+ Misses       3259     3258       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cmichi cmichi requested a review from a team as a code owner January 26, 2024 10:29
--features e2e-tests \
--manifest-path integration-tests/flipper/Cargo.toml \
e2e_test_deployed_contract \
-- --ignored --nocapture
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just thinking if this logic could be moved to an e2e/integration test for Ink instead of the CI workflow. This change would enable us to run it locally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean as an ink! e2e test that directly uses the cargo-contract crates to build and instantiate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my idea with the e2e test in flipper was to illustrate how to test a contract on-chain, this doesn't necessarily require having to build the contract beforehand.

Since the integration-tests/ end up on ink-examples, I'd like to avoid putting non-user relevant things there.

@cmichi cmichi merged commit 1ea20a2 into master Jan 29, 2024
23 checks passed
@cmichi cmichi deleted the cmichi-reexport-contractcallbuilder branch January 29, 2024 14:07
@SkymanOne SkymanOne mentioned this pull request Feb 8, 2024
@SkymanOne SkymanOne mentioned this pull request Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants