-
Notifications
You must be signed in to change notification settings - Fork 8
feat(contracts)!: experimental support for pallet-revive
#479
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
Merged
Merged
Changes from 46 commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
f374613
explore revive + contracts
sinzii 34e6058
type updates, ensure pallet supports, tx executors, ...
sinzii 122c52d
add demo script, ensure contract presence
sinzii 7c926fd
fix specs
sinzii b83e86e
fix events
sinzii 3acd450
Merge branch 'main' into expore-revive
sinzii d067f20
fix conflicts
sinzii 0391a13
fix build failed
sinzii 81ce634
regenerate types & add TODO
sinzii 34ece60
update script
sinzii d125ccc
fix specs & storage deposit
sinzii cbfa28b
fix e2e
sinzii 578f5c4
fix e2e
sinzii 56476f3
Add utils needed when creating contract address
1cedrus a91bf64
Validate salt when deploy contract with pallet-revive
1cedrus 545e26e
Add events handler for pallet-revive
1cedrus b36025f
Add e2e tests
1cedrus a1e3ed7
Add github action to run e2e-tests
1cedrus 22bd7c6
Use code for wasm and contract_binary
1cedrus 9276e09
Add ink metadata v6
1cedrus b5bf93f
Fix wrong config github action
1cedrus 2a24487
Add e2e-tests for errors
1cedrus 5b0fdd1
Validate storageLimitDeposit when call tx in pallet-revive
1cedrus 650a276
Resolve e2e-tests errors
1cedrus fdfe225
Update the validation check of storageDepositLimit
1cedrus e748851
support contract storage api
sinzii 67661f4
rename name methods
sinzii 18d3012
update types
sinzii c333765
refactoring
sinzii db6c11c
refactoring utils
sinzii e088487
Add unit tests
1cedrus c6fe9ec
Add contract address validation
1cedrus 45fe343
Add unit tests for create contractAddress utils
1cedrus 3c3ea0a
clean up create2
sinzii cbe5353
fix imports
sinzii 46f97a2
add generateRandomHex
sinzii b8bac92
use generateRandomHex
sinzii 12d7795
rename files
sinzii 04d8cc3
validate salt as 32 bytes
sinzii 46573bf
Fix ensure valid contract adddress
1cedrus de2ad31
Add validation for code hash or code
1cedrus c64fa22
Refactor code and remove todo!
1cedrus 414eb35
Fix wrong config e2e-tests
1cedrus 9afb896
Resolve error
1cedrus 0da1dc6
Remove parseRawMetadata
1cedrus 270de4e
Refactor code
1cedrus eab8956
formatting
sinzii 47e0264
refactoring & renaming
sinzii 8e04c7f
rename field & refactoring
sinzii 520f931
rename & refactoring
sinzii dc690c5
refactoring examples
sinzii 784ed49
fix ts complains
sinzii db275da
refactoring, move inputData for easy access
sinzii bbb5fcc
update example script
sinzii 435c709
add example interact with psp22
sinzii baf274d
inkv6 version check
sinzii 7941279
Merge remote-tracking branch 'origin/main' into feat/pallet-revive-in…
sinzii 3af7d3b
add psp22 v6 example
sinzii f1371df
use DedotClient
sinzii fd76873
fix unit tests
sinzii 86ad557
verify event emitted
sinzii 15ec357
update types
sinzii 41bbcc7
fix e2e
sinzii c924b61
Refactor code
1cedrus 867118d
remove logs
sinzii 7b3b76b
add assertion
sinzii f4ca517
fix check code & code-hash
sinzii 3d11b65
fix inkv5 examples
sinzii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| name: E2E Contracts API Tests | ||
|
|
||
| on: | ||
| push: | ||
| workflow_dispatch: | ||
| merge_group: | ||
|
|
||
| jobs: | ||
| e2e-tests: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| node-version: [18.x] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| cache: 'yarn' | ||
| - run: yarn install --immutable | ||
| - run: yarn build | ||
| - name: Download executables | ||
| run: | | ||
| curl -L -O https://github.com/paritytech/substrate-contracts-node/releases/download/v0.42.0/substrate-contracts-node-linux.tar.gz | ||
| tar -xzf substrate-contracts-node-linux.tar.gz | ||
| mv ./substrate-contracts-node-linux/substrate-contracts-node ./substrate-contracts-node | ||
| chmod +x substrate-contracts-node | ||
|
|
||
| curl -L -O https://github.com/use-ink/ink-node/releases/download/v0.43.2/ink-node-linux.tar.gz | ||
| tar -xzf ink-node-linux.tar.gz | ||
| mv ./ink-node-linux/ink-node ./ink-node | ||
| chmod +x ink-node | ||
|
|
||
| - name: Spawn networks | ||
| run: | | ||
| export PATH=$(pwd):$PATH | ||
| export RUST_BACKTRACE=full | ||
| ./ink-node --rpc-port=9955 & | ||
| ./substrate-contracts-node --dev --rpc-port=9944 & | ||
|
|
||
| chmod +x ./e2e/contracts/wait-for-port.sh | ||
| ./e2e/contracts/wait-for-port.sh 9944 30 | ||
| ./e2e/contracts/wait-for-port.sh 9955 30 | ||
|
|
||
| - name: Run tests | ||
| run: yarn workspace e2e-contracts run e2e:test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "name": "e2e-contracts", | ||
| "author": "Tung Vu <tung@dedot.dev>", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "e2e:test": "npx vitest --watch=false --no-file-parallelism" | ||
| }, | ||
| "dependencies": { | ||
| "@dedot/chaintypes": "^0.101.0", | ||
| "@polkadot/keyring": "^13.5.1", | ||
| "dedot": "workspace:*" | ||
| }, | ||
| "license": "Apache-2.0" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ## Contracts | ||
|
|
||
| ### Generate types for `flipper` contracts | ||
| ```shell | ||
| # Run from project's root folder | ||
| yarn cli typink -m ./e2e/contracts/src/contracts/flipper_v5.json -o ./e2e/contracts/src/contracts/ | ||
| ``` |
58 changes: 58 additions & 0 deletions
58
e2e/contracts/src/contracts/flipper/constructor-query.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Generated by dedot cli | ||
|
|
||
| import type { Hash, Result } from 'dedot/codecs'; | ||
| import type { | ||
| ConstructorCallOptions, | ||
| ContractInstantiateResult, | ||
| GenericConstructorCallResult, | ||
| GenericConstructorQuery, | ||
| GenericConstructorQueryCall, | ||
| } from 'dedot/contracts'; | ||
| import type { GenericSubstrateApi } from 'dedot/types'; | ||
| import type { FlipperFlipperError } from './types.js'; | ||
|
|
||
| export interface ConstructorQuery<ChainApi extends GenericSubstrateApi> extends GenericConstructorQuery<ChainApi> { | ||
| /** | ||
| * Creates a new flipper smart contract initialized with the given value. | ||
| * | ||
| * @param {boolean} initValue | ||
| * @param {ConstructorCallOptions} options | ||
| * | ||
| * @selector 0x9bae9d5e | ||
| **/ | ||
| new: GenericConstructorQueryCall< | ||
| ChainApi, | ||
| ( | ||
| initValue: boolean, | ||
| options?: ConstructorCallOptions, | ||
| ) => Promise<GenericConstructorCallResult<[], ContractInstantiateResult<ChainApi>>> | ||
| >; | ||
|
|
||
| /** | ||
| * Creates a new flipper smart contract initialized to `false`. | ||
| * | ||
| * @param {ConstructorCallOptions} options | ||
| * | ||
| * @selector 0x61ef7e3e | ||
| **/ | ||
| newDefault: GenericConstructorQueryCall< | ||
| ChainApi, | ||
| (options?: ConstructorCallOptions) => Promise<GenericConstructorCallResult<[], ContractInstantiateResult<ChainApi>>> | ||
| >; | ||
|
|
||
| /** | ||
| * Creates a new flipper smart contract with the value being calculate using provided seed. | ||
| * | ||
| * @param {Hash} seed | ||
| * @param {ConstructorCallOptions} options | ||
| * | ||
| * @selector 0x6d4cae81 | ||
| **/ | ||
| fromSeed: GenericConstructorQueryCall< | ||
| ChainApi, | ||
| ( | ||
| seed: Hash, | ||
| options?: ConstructorCallOptions, | ||
| ) => Promise<GenericConstructorCallResult<Result<[], FlipperFlipperError>, ContractInstantiateResult<ChainApi>>> | ||
| >; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Generated by dedot cli | ||
|
|
||
| import type { Hash } from 'dedot/codecs'; | ||
| import type { | ||
| ConstructorTxOptions, | ||
| GenericConstructorTx, | ||
| GenericConstructorTxCall, | ||
| GenericInstantiateSubmittableExtrinsic, | ||
| } from 'dedot/contracts'; | ||
| import type { GenericSubstrateApi } from 'dedot/types'; | ||
|
|
||
| export interface ConstructorTx<ChainApi extends GenericSubstrateApi> extends GenericConstructorTx<ChainApi> { | ||
| /** | ||
| * Creates a new flipper smart contract initialized with the given value. | ||
| * | ||
| * @param {boolean} initValue | ||
| * @param {ConstructorTxOptions} options | ||
| * | ||
| * @selector 0x9bae9d5e | ||
| **/ | ||
| new: GenericConstructorTxCall< | ||
| ChainApi, | ||
| (initValue: boolean, options: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ChainApi> | ||
| >; | ||
|
|
||
| /** | ||
| * Creates a new flipper smart contract initialized to `false`. | ||
| * | ||
| * @param {ConstructorTxOptions} options | ||
| * | ||
| * @selector 0x61ef7e3e | ||
| **/ | ||
| newDefault: GenericConstructorTxCall< | ||
| ChainApi, | ||
| (options: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ChainApi> | ||
| >; | ||
|
|
||
| /** | ||
| * Creates a new flipper smart contract with the value being calculate using provided seed. | ||
| * | ||
| * @param {Hash} seed | ||
| * @param {ConstructorTxOptions} options | ||
| * | ||
| * @selector 0x6d4cae81 | ||
| **/ | ||
| fromSeed: GenericConstructorTxCall< | ||
| ChainApi, | ||
| (seed: Hash, options: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ChainApi> | ||
| >; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Generated by dedot cli | ||
|
|
||
| import type { GenericContractEvent, GenericContractEvents } from 'dedot/contracts'; | ||
| import type { GenericSubstrateApi } from 'dedot/types'; | ||
|
|
||
| export interface ContractEvents<ChainApi extends GenericSubstrateApi> extends GenericContractEvents<ChainApi> { | ||
| /** | ||
| * Emitted when the flip function is called. | ||
| * | ||
| * @signature_topic: 0x0a39b5ca0b8b3a5172476100ae7b9168b269cc91d5648efe180c75d935d3e886 | ||
| **/ | ||
| Flipped: GenericContractEvent< | ||
| 'Flipped', | ||
| { | ||
| /** | ||
| * The previous state of the flip. | ||
| * | ||
| * @indexed: false | ||
| **/ | ||
| old: boolean; | ||
| /** | ||
| * The new state of the flip. | ||
| * | ||
| * @indexed: false | ||
| **/ | ||
| new: boolean; | ||
| } | ||
| >; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Generated by dedot cli | ||
|
|
||
| import type { SubstrateApi } from 'dedot/chaintypes'; | ||
| import type { GenericContractApi, WithLazyStorage } from 'dedot/contracts'; | ||
| import type { RpcVersion, VersionedGenericSubstrateApi } from 'dedot/types'; | ||
| import { ConstructorQuery } from './constructor-query.js'; | ||
| import { ConstructorTx } from './constructor-tx.js'; | ||
| import { ContractEvents } from './events.js'; | ||
| import { ContractQuery } from './query.js'; | ||
| import { ContractTx } from './tx.js'; | ||
| import type { Flipper, InkPrimitivesLangError } from './types.js'; | ||
|
|
||
| export * from './types.js'; | ||
|
|
||
| /** | ||
| * @name: FlipperContractApi | ||
| * @contractName: flipper | ||
| * @contractVersion: 5.0.0 | ||
| * @authors: Parity Technologies <admin@parity.io> | ||
| * @language: ink! 5.0.0 | ||
| **/ | ||
| export interface FlipperContractApi< | ||
| Rv extends RpcVersion = RpcVersion, | ||
| ChainApi extends VersionedGenericSubstrateApi = SubstrateApi, | ||
| > extends GenericContractApi<Rv, ChainApi> { | ||
| query: ContractQuery<ChainApi[Rv]>; | ||
| tx: ContractTx<ChainApi[Rv]>; | ||
| constructorQuery: ConstructorQuery<ChainApi[Rv]>; | ||
| constructorTx: ConstructorTx<ChainApi[Rv]>; | ||
| events: ContractEvents<ChainApi[Rv]>; | ||
| storage: { | ||
| root(): Promise<Flipper>; | ||
| lazy(): WithLazyStorage<Flipper>; | ||
| }; | ||
|
|
||
| types: { | ||
| RootStorage: Flipper; | ||
| LazyStorage: WithLazyStorage<Flipper>; | ||
| LangError: InkPrimitivesLangError; | ||
| ChainApi: ChainApi[Rv]; | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Generated by dedot cli | ||
|
|
||
| import type { Hash, Result } from 'dedot/codecs'; | ||
| import type { | ||
| ContractCallOptions, | ||
| ContractCallResult, | ||
| GenericContractCallResult, | ||
| GenericContractQuery, | ||
| GenericContractQueryCall, | ||
| } from 'dedot/contracts'; | ||
| import type { GenericSubstrateApi } from 'dedot/types'; | ||
| import type { FlipperFlipperError } from './types.js'; | ||
|
|
||
| export interface ContractQuery<ChainApi extends GenericSubstrateApi> extends GenericContractQuery<ChainApi> { | ||
| /** | ||
| * Flips the current value, value based on seed. | ||
| * | ||
| * @param {Hash} seed | ||
| * @param {ContractCallOptions} options | ||
| * | ||
| * @selector 0x847d0968 | ||
| **/ | ||
| flipWithSeed: GenericContractQueryCall< | ||
| ChainApi, | ||
| ( | ||
| seed: Hash, | ||
| options?: ContractCallOptions, | ||
| ) => Promise<GenericContractCallResult<Result<boolean, FlipperFlipperError>, ContractCallResult<ChainApi>>> | ||
| >; | ||
|
|
||
| /** | ||
| * Flips the current value of the Flipper's boolean. | ||
| * | ||
| * @param {ContractCallOptions} options | ||
| * | ||
| * @selector 0x633aa551 | ||
| **/ | ||
| flip: GenericContractQueryCall< | ||
| ChainApi, | ||
| (options?: ContractCallOptions) => Promise<GenericContractCallResult<[], ContractCallResult<ChainApi>>> | ||
| >; | ||
|
|
||
| /** | ||
| * Returns the current value of the Flipper's boolean. | ||
| * | ||
| * @param {ContractCallOptions} options | ||
| * | ||
| * @selector 0x2f865bd9 | ||
| **/ | ||
| get: GenericContractQueryCall< | ||
| ChainApi, | ||
| (options?: ContractCallOptions) => Promise<GenericContractCallResult<boolean, ContractCallResult<ChainApi>>> | ||
| >; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Generated by dedot cli | ||
|
|
||
| import type { Hash } from 'dedot/codecs'; | ||
| import type { | ||
| ContractSubmittableExtrinsic, | ||
| ContractTxOptions, | ||
| GenericContractTx, | ||
| GenericContractTxCall, | ||
| } from 'dedot/contracts'; | ||
| import type { GenericSubstrateApi } from 'dedot/types'; | ||
|
|
||
| export interface ContractTx<ChainApi extends GenericSubstrateApi> extends GenericContractTx<ChainApi> { | ||
| /** | ||
| * Flips the current value, value based on seed. | ||
| * | ||
| * @param {Hash} seed | ||
| * @param {ContractTxOptions} options | ||
| * | ||
| * @selector 0x847d0968 | ||
| **/ | ||
| flipWithSeed: GenericContractTxCall< | ||
| ChainApi, | ||
| (seed: Hash, options: ContractTxOptions) => ContractSubmittableExtrinsic<ChainApi> | ||
| >; | ||
|
|
||
| /** | ||
| * Flips the current value of the Flipper's boolean. | ||
| * | ||
| * @param {ContractTxOptions} options | ||
| * | ||
| * @selector 0x633aa551 | ||
| **/ | ||
| flip: GenericContractTxCall<ChainApi, (options: ContractTxOptions) => ContractSubmittableExtrinsic<ChainApi>>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Generated by dedot cli | ||
|
|
||
| export type Flipper = { value: boolean }; | ||
|
|
||
| export type InkPrimitivesLangError = 'CouldNotReadInput'; | ||
|
|
||
| export type FlipperFlipperError = 'ZeroSum'; | ||
|
|
||
| export type InkEnvNoChainExtension = null; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { LegacyClient } from 'dedot'; | ||
|
|
||
| declare global { | ||
| var contractsClient: LegacyClient; | ||
| var reviveClient: LegacyClient; | ||
| } | ||
|
|
||
| export {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { LegacyClient, WsProvider } from 'dedot'; | ||
| import { afterAll, beforeAll } from 'vitest'; | ||
| import { devPairs } from './utils'; | ||
|
|
||
| const CONTRACTS_NODE_ENDPOINT = 'ws://127.0.0.1:9944'; | ||
| const INK_NODE_ENDPOINT = 'ws://127.0.0.1:9955'; | ||
|
|
||
| beforeAll(async () => { | ||
| console.log(`Connect to ${CONTRACTS_NODE_ENDPOINT}`); | ||
| global.contractsClient = await LegacyClient.new(new WsProvider(CONTRACTS_NODE_ENDPOINT)); | ||
|
|
||
| console.log(`Connect to ${INK_NODE_ENDPOINT}`); | ||
| global.reviveClient = await LegacyClient.new(new WsProvider(INK_NODE_ENDPOINT)); | ||
|
|
||
| const alicePair = devPairs().alice; | ||
| await reviveClient.tx.revive.mapAccount().signAndSend(alicePair).untilFinalized(); | ||
| }, 120_000); | ||
|
|
||
| afterAll(async () => { | ||
| await global.contractsClient.disconnect(); | ||
| console.log(`Disconnected from ${CONTRACTS_NODE_ENDPOINT}`); | ||
|
|
||
| await global.reviveClient.disconnect(); | ||
| console.log(`Disconnected from ${INK_NODE_ENDPOINT}`); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.