-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improvements and testing for RLP ink! contracts (#2375)
* feat(generator): add DECODE and RETURN const to trait message generation for tests to build * test: compile tests for RLP and ALL encoding -- wip * feat(generator): wip RLP encoding for trait messages * fix(generator): don't double generate message with encoding ALL when user provided * feat(primitives): AccountId derives RlpEncodable * test(integration): RLP cross-contract call ink! <> ink!; wip * build(deps): use consistent workspace import format * test(integration): update RLP test to use revive * test(integration): refactor RLP test to use OriginFor. Cleanup comments and unused imports * test(integration): rlp cross-contract test uses revive -- fails with DecodeError * feat: invoke contract uses DecodeDispatch return -- wip * Revert "feat: invoke contract uses DecodeDispatch return -- wip" This reverts commit 01e4f46. * fix(codegen): expected function signature of rlp_return_value * test(e2e): setup hardhat-revive for solidity testing * test(e2e): wip .sol calling ink! contract * merge master * feat(e2e): add node `url` to `Client` * test(e2e): solidity calls ink!, setup eth-rpc, setup, and run hardhat script * chore(spellcheck): include alith * test(e2e): verify value after flip from sol * test(e2e): refactor to e2e_tests.rs file * test(e2e): refactor hardhat command + general cleanup * chore: remove comment * style(deps): match base branch whitespace * style(tests): add new line to UI test * chore: address review; add whitespace, fix version, initial TODOs
- Loading branch information
Showing
28 changed files
with
4,985 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
110 | ||
|
||
ABI | ||
alith | ||
AST | ||
BLAKE2 | ||
BLAKE2b | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
65 changes: 65 additions & 0 deletions
65
crates/ink/tests/ui/contract/pass/message-selector-encoding-all.rs
This file contains 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,65 @@ | ||
use contract::Contract; | ||
|
||
#[ink::contract(abi_encoding = "all")] | ||
mod contract { | ||
#[ink(storage)] | ||
pub struct Contract {} | ||
|
||
#[ink::trait_definition] | ||
pub trait Messages { | ||
#[ink(message, selector = 1)] | ||
fn message_1(&self); | ||
} | ||
|
||
impl Contract { | ||
#[ink(constructor)] | ||
pub fn constructor() -> Self { | ||
Self {} | ||
} | ||
|
||
#[ink(message, selector = 0xC0DE_CAFE)] | ||
pub fn message_2(&self) {} | ||
|
||
#[ink(message)] | ||
pub fn message_3(&self) {} | ||
} | ||
|
||
impl Messages for Contract { | ||
#[ink(message, selector = 1)] | ||
fn message_1(&self) {} | ||
} | ||
|
||
#[ink::trait_definition] | ||
pub trait Messages2 { | ||
#[ink(message, selector = 0x12345678)] | ||
fn message_4(&self); | ||
} | ||
|
||
impl Messages2 for Contract { | ||
#[ink(message, selector = 0x12345678)] | ||
fn message_4(&self) {} | ||
} | ||
} | ||
|
||
fn main() { | ||
assert_eq!( | ||
<Contract as ::ink::reflect::DispatchableMessageInfo<1_u32>>::SELECTOR, | ||
1_u32.to_be_bytes(), | ||
); | ||
assert_eq!( | ||
<Contract as ::ink::reflect::DispatchableMessageInfo<0xC0DE_CAFE_u32>>::SELECTOR, | ||
0xC0DE_CAFE_u32.to_be_bytes(), | ||
); | ||
|
||
// manually calculated "message_3" | ||
const INHERENT_ID_RLP: u32 = 0x0cd0f0f1; | ||
assert_eq!( | ||
<Contract as ::ink::reflect::DispatchableMessageInfo<INHERENT_ID_RLP>>::SELECTOR, | ||
[0x0C, 0xD0, 0xF0, 0xF1], | ||
); | ||
|
||
assert_eq!( | ||
<Contract as ::ink::reflect::DispatchableMessageInfo<0x12345678_u32>>::SELECTOR, | ||
0x12345678_u32.to_be_bytes(), | ||
); | ||
} |
65 changes: 65 additions & 0 deletions
65
crates/ink/tests/ui/contract/pass/message-selector-encoding-rlp.rs
This file contains 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,65 @@ | ||
use contract::Contract; | ||
|
||
#[ink::contract(abi_encoding = "rlp")] | ||
mod contract { | ||
#[ink(storage)] | ||
pub struct Contract {} | ||
|
||
#[ink::trait_definition] | ||
pub trait Messages { | ||
#[ink(message, selector = 1)] | ||
fn message_1(&self); | ||
} | ||
|
||
impl Contract { | ||
#[ink(constructor)] | ||
pub fn constructor() -> Self { | ||
Self {} | ||
} | ||
|
||
#[ink(message, selector = 0xC0DE_CAFE)] | ||
pub fn message_2(&self) {} | ||
|
||
#[ink(message)] | ||
pub fn message_3(&self) {} | ||
} | ||
|
||
impl Messages for Contract { | ||
#[ink(message, selector = 1)] | ||
fn message_1(&self) {} | ||
} | ||
|
||
#[ink::trait_definition] | ||
pub trait Messages2 { | ||
#[ink(message, selector = 0x12345678)] | ||
fn message_4(&self); | ||
} | ||
|
||
impl Messages2 for Contract { | ||
#[ink(message, selector = 0x12345678)] | ||
fn message_4(&self) {} | ||
} | ||
} | ||
|
||
fn main() { | ||
assert_eq!( | ||
<Contract as ::ink::reflect::DispatchableMessageInfo<1_u32>>::SELECTOR, | ||
1_u32.to_be_bytes(), | ||
); | ||
assert_eq!( | ||
<Contract as ::ink::reflect::DispatchableMessageInfo<0xC0DE_CAFE_u32>>::SELECTOR, | ||
0xC0DE_CAFE_u32.to_be_bytes(), | ||
); | ||
|
||
// manually calculated "message_3" | ||
const INHERENT_ID_RLP: u32 = 0x0cd0f0f1; | ||
assert_eq!( | ||
<Contract as ::ink::reflect::DispatchableMessageInfo<INHERENT_ID_RLP>>::SELECTOR, | ||
[0x0C, 0xD0, 0xF0, 0xF1], | ||
); | ||
|
||
assert_eq!( | ||
<Contract as ::ink::reflect::DispatchableMessageInfo<0x12345678_u32>>::SELECTOR, | ||
0x12345678_u32.to_be_bytes(), | ||
); | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.