-
Notifications
You must be signed in to change notification settings - Fork 255
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
Double map and plain storage support, introduce macros #93
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff! Could you add a couple of tests for the double map and the plain storage?
I added a proc-macro to generate client code for substrate modules. I'll look into generating test cases too which should fix your comment. |
Sorry, this PR has gotten a little out of hand. It still needs more field testing, and the #[module]
pub trait Balances: System {
type Balance: Parameter
+ Member
+ AtLeast32Bit
+ codec::Codec
+ Default
+ Copy
+ MaybeSerialize
+ Debug
+ From<<Self as System>::BlockNumber>;
}
#[derive(Clone, Decode, Default)]
pub struct AccountData<Balance> {
pub free: Balance,
pub reserved: Balance,
pub misc_frozen: Balance,
pub fee_frozen: Balance,
}
#[derive(Encode, Store)]
pub struct AccountStore<'a, T: Balances> {
#[store(returns = AccountData<T::Balance>)]
pub account_id: &'a <T as System>::AccountId,
}
#[derive(Call, Encode)]
pub struct TransferCall<'a, T: Balances> {
pub to: &'a <T as System>::Address,
#[codec(compact)]
pub amount: T::Balance,
}
#[derive(Debug, Decode, Eq, Event, PartialEq)]
pub struct TransferEvent<T: Balances> {
pub from: <T as System>::AccountId,
pub to: <T as System>::AccountId,
pub amount: T::Balance,
}
impl Balances for KusamaRuntime {
type Balance = u128;
}
subxt_test!({
name: transfer_test_case,
runtime: KusamaRuntime,
account: Alice,
step: {
state: {
alice: AccountStore { account_id: &alice },
bob: AccountStore { account_id: &bob },
},
call: TransferCall {
to: &bob,
amount: 10_000,
},
event: TransferEvent {
from: alice.clone(),
to: bob.clone(),
amount: 10_000,
},
assert: {
assert_eq!(pre.alice.free, post.alice.free - 10_000);
assert_eq!(pre.bob.free, post.bob.free + 10_000);
},
},
}); |
Mmh one problem is that the nonces are wrong when running multiple tests in parallel. Is it possible to disable nonce checking on dev chains? |
https://stackoverflow.com/questions/44947914/how-to-limit-the-number-of-test-threads-in-cargo-toml Apparently, there was this rust-lang/rust#42684 which was resolved with the introduction of this https://crates.io/crates/serial_test |
Due to possible races it looks like it's the only way to do it. If we shared the client and set the account based on the thread id, arbitrary interleaving of tests will cause failures. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the proc macros. Though still need a test case for double_map
which is the ostensible purpose of this PR 😄
Is it ok if I just add a test for plain? The system, balances and contracts modules don't contain any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Simplifies trait bounds.
Allows setting a custom client.
Adds support for plain and double-map storage items.