-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grant Wuerker
committed
Mar 15, 2023
1 parent
616b58a
commit 8a72457
Showing
6 changed files
with
148 additions
and
135 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// error: cannot glob import from ingot | ||
// use std::{abi::Abi, evm} | ||
|
||
use std::abi::{Abi, MemoryBuffer} | ||
use std::evm | ||
|
||
const HASH_SCRATCH_SPACE_START: u256 = 0x00 | ||
const HASH_SCRATCH_SPACE_SIZE: u256 = 64 | ||
|
||
#test | ||
unsafe fn u256_decode() { | ||
evm::mstore(offset: HASH_SCRATCH_SPACE_START, value: 26) | ||
evm::mstore(offset: HASH_SCRATCH_SPACE_START + 32, value: 42) | ||
|
||
let mut buf: MemoryBuffer = MemoryBuffer::new( | ||
start: HASH_SCRATCH_SPACE_START, | ||
end: HASH_SCRATCH_SPACE_START + HASH_SCRATCH_SPACE_SIZE | ||
) | ||
|
||
assert u256::decode(buf) == 26 | ||
assert u256::decode(buf) == 42 | ||
} | ||
|
||
#test | ||
unsafe fn u256_encode() { | ||
let mut buf: MemoryBuffer = MemoryBuffer::new( | ||
start: HASH_SCRATCH_SPACE_START, | ||
end: HASH_SCRATCH_SPACE_START + HASH_SCRATCH_SPACE_SIZE | ||
) | ||
|
||
26.encode(buf) | ||
42.encode(buf) | ||
|
||
assert evm::mload(offset: HASH_SCRATCH_SPACE_START) == 26 | ||
assert evm::mload(offset: HASH_SCRATCH_SPACE_START + 32) == 42 | ||
} | ||
|
||
type MyArray = Array<u256, 2> | ||
type MyTuple = (u256, u256) | ||
|
||
#test | ||
unsafe fn array_decode() { | ||
evm::mstore(offset: HASH_SCRATCH_SPACE_START, value: 26) | ||
evm::mstore(offset: HASH_SCRATCH_SPACE_START + 32, value: 42) | ||
|
||
let mut buf: MemoryBuffer = MemoryBuffer::new( | ||
start: HASH_SCRATCH_SPACE_START, | ||
end: HASH_SCRATCH_SPACE_START + HASH_SCRATCH_SPACE_SIZE | ||
) | ||
|
||
// parser panics | ||
// let my_array: = Array<u256, 2>::decode(buf) | ||
let my_array: MyArray = MyArray::decode(buf) | ||
assert my_array[0] == 26 | ||
assert my_array[1] == 42 | ||
} | ||
|
||
#test | ||
unsafe fn tuple_decode() { | ||
evm::mstore(offset: HASH_SCRATCH_SPACE_START, value: 26) | ||
evm::mstore(offset: HASH_SCRATCH_SPACE_START + 32, value: 42) | ||
|
||
let mut buf: MemoryBuffer = MemoryBuffer::new( | ||
start: HASH_SCRATCH_SPACE_START, | ||
end: HASH_SCRATCH_SPACE_START + HASH_SCRATCH_SPACE_SIZE | ||
) | ||
|
||
// parser panics | ||
// let my_tuple: (u256, u256) = (u256, u256)::decode(buf) | ||
let my_tuple: MyTuple = MyTuple::decode(buf) | ||
assert my_tuple.item0 == 26 | ||
assert my_tuple.item1 == 42 | ||
} |
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