Skip to content

Commit

Permalink
hacking
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Wuerker committed Jul 3, 2023
1 parent f4b3ca0 commit a6148af
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions crates/tests/fixtures/files/abi.fe
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::buf::{
RawCallBuffer
}
use std::evm
use std::traits::Max

contract AbiDecodeU256 {
pub unsafe fn __call__(ctx: Context) {
Expand All @@ -23,6 +24,19 @@ contract AbiDecodeU256 {
}
}

contract AbiDecodeU128 {
pub unsafe fn __call__(ctx: Context) {
let mut reader: CalldataReader = ctx.calldata_reader()
let value: u128 = u128::decode(reader)

let mut buf: MemoryBuffer = MemoryBuffer::new(len: 32)
let mut writer: MemoryBufferWriter = buf.writer()
writer.write(value)

evm::return_mem(buf)
}
}

// #test
// unsafe fn u256_decode() {
// let mut buf: MemoryBuffer = MemoryBuffer::new(len: 64)
Expand Down Expand Up @@ -66,6 +80,21 @@ fn u256_decode(mut ctx: Context) {
assert reader.read_u256() == 42
}

#test
fn u128_decode_invalid(mut ctx: Context) {
let decoder: address = address(AbiDecodeU128.create(ctx, 0))
let mut buf: RawCallBuffer = RawCallBuffer::new(
input_len: 32,
output_len: 32
)

let mut writer: MemoryBufferWriter = buf.writer()
writer.write(value: u256::max())

assert not ctx.raw_call(addr: decoder, value: 0, buf)
}


// type MyArray = Array<u256, 2>
// type MyTuple = (u256, u256)

Expand Down

0 comments on commit a6148af

Please sign in to comment.