-
Notifications
You must be signed in to change notification settings - Fork 692
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
Contracts: seal0::balance
should return the free balance
#1254
Changes from 2 commits
46dcca8
6259026
be65ff7
84155b5
ce72ef3
2edad0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
(module | ||
(import "seal0" "seal_balance" (func $seal_balance (param i32 i32))) | ||
(import "env" "memory" (memory 1 1)) | ||
|
||
;; [0, 8) reserved for $seal_balance output | ||
|
||
;; [8, 16) length of the buffer for $seal_balance | ||
(data (i32.const 8) "\08") | ||
|
||
;; [16, inf) zero initialized | ||
|
||
(func $assert (param i32) | ||
(block $ok | ||
(br_if $ok | ||
(get_local 0) | ||
) | ||
(unreachable) | ||
) | ||
) | ||
|
||
(func (export "deploy")) | ||
|
||
(func (export "call") | ||
(call $seal_balance (i32.const 0) (i32.const 8)) | ||
|
||
;; Balance should be encoded as a u64. | ||
(call $assert | ||
(i32.eq | ||
(i32.load (i32.const 8)) | ||
(i32.const 8) | ||
) | ||
) | ||
|
||
;; Assert the free balance to be zero. | ||
(call $assert | ||
(i64.eq | ||
(i64.load (i32.const 0)) | ||
(i64.const 0) | ||
) | ||
) | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ use frame_support::{ | |
storage::{with_transaction, TransactionOutcome}, | ||
traits::{ | ||
fungible::{Inspect, Mutate}, | ||
tokens::Preservation, | ||
tokens::{Fortitude, Preservation}, | ||
Contains, OriginTrait, Randomness, Time, | ||
}, | ||
weights::Weight, | ||
|
@@ -1367,7 +1367,11 @@ where | |
} | ||
|
||
fn balance(&self) -> BalanceOf<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch, looks like this is a regression from paritytech/substrate#14020 fn balance(&self) -> BalanceOf<T> {
- T::Currency::free_balance(&self.top_frame().account_id)
+ T::Currency::balance(&self.top_frame().account_id)
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are different traits. On the |
||
T::Currency::balance(&self.top_frame().account_id) | ||
T::Currency::reducible_balance( | ||
&self.top_frame().account_id, | ||
Preservation::Preserve, | ||
Fortitude::Polite, | ||
) | ||
} | ||
|
||
fn value_transferred(&self) -> BalanceOf<T> { | ||
|
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.
isn't it simpler not to modify the fixture but to add ED to the transferred balance?
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.
Hmm, not sure what you mean, this does add the ED to the transferred balance. How would I do that without modifying the fixture?
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.
I mean the fixture is broken, given
seal_balance
should only return free balance: It tries to send away all free balance but expects the transfer to fail. Which should never fail. Hence we need to modify it anyways.