This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Merged
WASM math test #6305
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Submodule wasm-tests
updated
from 330f74 to 85e76c
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -414,3 +414,37 @@ fn storage_read() { | |
assert_eq!(gas_left, U256::from(99682)); | ||
assert_eq!(Address::from(&result[12..32]), address); | ||
} | ||
|
||
|
||
// Tests that contract's ability to read from a storage | ||
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. looks like there should be a different commentary.. |
||
// Test prepopulates address into storage, than executes a contract which read that address from storage and write this address into result | ||
#[test] | ||
fn math_add() { | ||
::ethcore_logger::init_log(); | ||
let code = load_sample!("math.wasm"); | ||
|
||
let mut params = ActionParams::default(); | ||
params.gas = U256::from(100_000); | ||
params.code = Some(Arc::new(code)); | ||
|
||
let mut args = [0u8; 64]; | ||
let arg_a = U256::from_dec_str("999999999999999999999999999999").unwrap(); | ||
let arg_b = U256::from_dec_str("888888888888888888888888888888").unwrap(); | ||
arg_a.to_big_endian(&mut args[0..32]); | ||
arg_b.to_big_endian(&mut args[32..64]); | ||
params.data = Some(args.to_vec()); | ||
|
||
let (gas_left, result) = { | ||
let mut interpreter = wasm_interpreter(); | ||
let result = interpreter.exec(params, &mut FakeExt::new()).expect("Interpreter to execute without any errors"); | ||
match result { | ||
GasLeft::Known(_) => { panic!("storage_read should return payload"); }, | ||
GasLeft::NeedsReturn { gas_left: gas, data: result, apply_state: _apply } => (gas, result.to_vec()), | ||
} | ||
}; | ||
|
||
let sum: U256 = (&result[..]).into(); | ||
|
||
assert_eq!(gas_left, U256::from(96284)); | ||
assert_eq!(sum, U256::from_dec_str("1888888888888888888888888888887").unwrap()); | ||
} |
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.
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.
is that actually how it's supposed to work?
[a b c d e f g h] -> [d c b a h g f e]
instead of [h g f e d c b a]
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.
Stack reverses the parameter ordering, so first parameter is popped last