From 75ab77a03ddac2b5c3b89cfa7d436651f59df51e Mon Sep 17 00:00:00 2001 From: Alberto Lerda Date: Thu, 29 Jun 2023 09:42:44 +0200 Subject: [PATCH] feat: encoding bool in ethereum ABI --- src/lua/crypto_ethereum.lua | 9 +++++++++ test/zencode/ethereum.bats | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/lua/crypto_ethereum.lua b/src/lua/crypto_ethereum.lua index 151a85d2c..e68cc639e 100644 --- a/src/lua/crypto_ethereum.lua +++ b/src/lua/crypto_ethereum.lua @@ -424,6 +424,15 @@ function encode(t, arg) end res = arg .. padding elseif t == 'bool' then + if iszen(type(arg)) then + arg = arg:octet():string() + end + if type(arg) == 'string' then + if arg ~= "true" and arg ~= "false" then + error(arg .. " is not a boolean value") + end + arg = arg ~= 'false' + end res = BIG.new(fif(arg, 1, 0)):fixed(32) elseif t == 'string' or t == 'bytes' then if iszen(type(arg)) then diff --git a/test/zencode/ethereum.bats b/test/zencode/ethereum.bats index 061fb9281..b64c4c69b 100644 --- a/test/zencode/ethereum.bats +++ b/test/zencode/ethereum.bats @@ -563,6 +563,46 @@ EOF assert_output '{"ethereum_abi_encoding":"00000000000000000000000077c2f9730b6c3341e1b71f76ecf19ba39e88f247000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000033233340000000000000000000000000000000000000000000000000000000000","hash":"pTFYbyovWkOT6CaHSRNCN7ySQ/AGbphs9WQnZ2JwPWQ="}' } +@test "Complex encoding" { + cat <