forked from vyperlang/vyper
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for vyperlang#743, ensuring we correctly right pad when a me…
…thod returns.
- Loading branch information
1 parent
4cd80db
commit 887fceb
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
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,33 @@ | ||
|
||
def test_correct_abi_right_padding(tester, w3, get_contract_with_gas_estimation): | ||
selfcall_code_6 = """ | ||
@public | ||
def hardtest(arg1: bytes[64], arg2: bytes[64]) -> bytes[128]: | ||
return concat(arg1, arg2) | ||
""" | ||
|
||
c = get_contract_with_gas_estimation(selfcall_code_6) | ||
|
||
assert c.hardtest(b"hello" * 5, b"hello" * 10) == b"hello" * 15 | ||
|
||
# Make sure underlying structe is correctly right padded | ||
classic_contract = c._classic_contract | ||
func = classic_contract.functions.hardtest(b"hello" * 5, b"hello" * 10) | ||
tx = func.buildTransaction() | ||
del tx['chainId'] | ||
del tx['gasPrice'] | ||
|
||
tx['from'] = w3.eth.accounts[0] | ||
res = w3.toBytes(hexstr=tester.call(tx)) | ||
|
||
static_offset = int.from_bytes(res[:32], 'big') | ||
assert static_offset == 32 | ||
|
||
dyn_section = res[static_offset:] | ||
assert len(dyn_section) % 32 == 0 # first right pad assert | ||
|
||
len_value = int.from_bytes(dyn_section[:32], 'big') | ||
|
||
assert len_value == len(b"hello" * 15) | ||
assert dyn_section[32: 32 + len_value] == b"hello" * 15 | ||
assert dyn_section[32 + len_value:] == b'\x00' * (len(dyn_section) - 32 - len_value) # second right pad assert |