mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-12 04:51:01 +00:00
Fix implementation for balance_of (#79)
The balance_of syscall is now available in pallet-revive. - Fix balance_of implementation to use correct runtime api - Add build_address_argument_store helper to be used for address arguments
This commit is contained in:
@@ -5,6 +5,15 @@ pragma solidity ^0.8;
|
||||
{
|
||||
"differential": true,
|
||||
"actions": [
|
||||
{
|
||||
"Upload": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "ValueTester"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Instantiate": {
|
||||
"value": 1024,
|
||||
@@ -23,31 +32,35 @@ pragma solidity ^0.8;
|
||||
"value": 123,
|
||||
"data": "3fa4f245"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "52da5fa0"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract Value {
|
||||
contract ValueTester {
|
||||
constructor() payable {}
|
||||
|
||||
function value() public payable returns (uint ret) {
|
||||
ret = msg.value;
|
||||
}
|
||||
|
||||
function balance_self() public view returns (uint ret) {
|
||||
ret = address(this).balance;
|
||||
}
|
||||
}
|
||||
|
||||
function balance_of(address _address) public view returns (uint ret) {
|
||||
ret = _address.balance;
|
||||
contract Value {
|
||||
constructor() payable {
|
||||
ValueTester tester = new ValueTester{value: msg.value}();
|
||||
|
||||
// own account
|
||||
assert(address(this).balance == 0);
|
||||
|
||||
// tester account
|
||||
assert(address(tester).balance == msg.value);
|
||||
assert(tester.balance_self() == msg.value);
|
||||
|
||||
// non-existant account
|
||||
assert(address(0xdeadbeef).balance == 0);
|
||||
}
|
||||
|
||||
function value() public payable returns (uint ret) {
|
||||
ret = msg.value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,32 +263,6 @@ fn create2_failure() {
|
||||
assert_eq!(output.flags, ReturnFlags::Revert);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn balance() {
|
||||
let (_, output) = assert_success(&Contract::value_balance_of(Default::default()), false);
|
||||
|
||||
let expected = U256::ZERO;
|
||||
let received = U256::from_be_slice(&output.data);
|
||||
assert_eq!(expected, received);
|
||||
|
||||
let expected = U256::from(54589);
|
||||
let (mut state, address) = State::new_deployed(Contract::value_balance_of(Default::default()));
|
||||
state.accounts_mut().get_mut(&address).unwrap().value = expected;
|
||||
|
||||
let contract = Contract::value_balance_of(address);
|
||||
let (_, output) = state
|
||||
.transaction()
|
||||
.with_default_account(&contract.pvm_runtime)
|
||||
.calldata(contract.calldata)
|
||||
.call();
|
||||
|
||||
assert_eq!(ReturnFlags::Success, output.flags);
|
||||
|
||||
let received = U256::from_be_slice(&output.data);
|
||||
assert_eq!(expected, received)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_code_size() {
|
||||
let contract = Contract::ext_code_size(Transaction::default_address());
|
||||
|
||||
Reference in New Issue
Block a user