From 77c56b381b8742331902bdc43503cfb29ca772a9 Mon Sep 17 00:00:00 2001 From: Gerald Bauer Date: Sun, 8 Jan 2023 17:46:04 +0100 Subject: [PATCH] up abi tests --- abicoder/lib/abicoder/version.rb | 2 +- abicoder/test/test_fixtures.rb | 21 ++++- test/abicoder/more.yml | 134 ++++++++++++++++++++++++++++--- 3 files changed, 146 insertions(+), 11 deletions(-) diff --git a/abicoder/lib/abicoder/version.rb b/abicoder/lib/abicoder/version.rb index 3a4c088..879e3e8 100644 --- a/abicoder/lib/abicoder/version.rb +++ b/abicoder/lib/abicoder/version.rb @@ -2,7 +2,7 @@ module ABICoder MAJOR = 1 MINOR = 0 - PATCH = 0 + PATCH = 1 VERSION = [MAJOR,MINOR,PATCH].join('.') def self.version diff --git a/abicoder/test/test_fixtures.rb b/abicoder/test/test_fixtures.rb index 191ac03..ee3d024 100644 --- a/abicoder/test/test_fixtures.rb +++ b/abicoder/test/test_fixtures.rb @@ -11,12 +11,31 @@ class TestFixtures < MiniTest::Test +## little helper to (recursively) convert 0x hex strings to binary strings +## other option to use binary in yaml is using !!binary with base64 encoding +def hex_to_bin( arg ) + if arg.is_a?( Array ) + arg.map { |item| hex_to_bin( item ) } + elsif arg.is_a?( String ) && arg =~ /\A0x[0-9a-fA-F]{2,}\z/ + hex = arg[2..-1] + bin = [hex].pack("H*") + puts " converting hex >#{arg}< to bin >#{bin.inspect}< #{bin.size} byte(s)" + bin + else + arg + end +end + + def assert_test( test ) types = test['types'] args = test['args'] hex = test['data'] + puts "==> testing #{types}...:" + args = hex_to_bin( args ) + types.zip( args ).each_with_index do |(type,arg),i| puts " [#{i}] #{type} => #{arg.inspect}" ## pp ABI::Type.parse( type ) @@ -43,7 +62,7 @@ def assert_test( test ) end -def test_basic +def xx_test_basic tests = read_yml( '../test/abicoder/basic.yml' ) puts " #{tests.size} test(s) in /test/abicoder/basic.yml" pp tests diff --git a/test/abicoder/more.yml b/test/abicoder/more.yml index b4c1b57..c869e9f 100644 --- a/test/abicoder/more.yml +++ b/test/abicoder/more.yml @@ -114,16 +114,23 @@ 0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000000' -## bool -- types: ['bool'] - args: [true] - data: '0000000000000000000000000000000000000000000000000000000000000001' - -## bool2 -- types: ['bool'] - args: [false] - data: '0000000000000000000000000000000000000000000000000000000000000000' +# comprehensive test +- types: ['int256', 'bytes', 'int256', 'bytes' ] + args: [5, + '0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b', + 3, + '0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'] + data: '0000000000000000000000000000000000000000000000000000000000000005 + 0000000000000000000000000000000000000000000000000000000000000080 + 0000000000000000000000000000000000000000000000000000000000000003 + 00000000000000000000000000000000000000000000000000000000000000e0 + 0000000000000000000000000000000000000000000000000000000000000040 + 131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b + 131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b + 0000000000000000000000000000000000000000000000000000000000000040 + 131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b + 131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' ## comprehensive test2 - types: ['int256','string','int256','int256','int256','int256[]' ] @@ -248,3 +255,112 @@ 0000000000000000000000000000000000000000000000000000000000000002 0000000000000000000000000000000000000000000000000000000000000042 0000000000000000000000000000000000000000000000000000000000001337' + + +## bool +- types: ['bool'] + args: [true] + data: '0000000000000000000000000000000000000000000000000000000000000001' + +## bool2 +- types: ['bool'] + args: [false] + data: '0000000000000000000000000000000000000000000000000000000000000000' + + +# string +- types: ['string'] + args: ['gavofyork'] + data: '0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000009 + 6761766f66796f726b0000000000000000000000000000000000000000000000' + +# bytes +- types: ['bytes'] + args: ['0x1234'] + data: '0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 1234000000000000000000000000000000000000000000000000000000000000' + +# bytes2 +- types: ['bytes'] + args: ['0x10000000000000000000000000000000000000000000000000000000000002'] + data: '0000000000000000000000000000000000000000000000000000000000000020 + 000000000000000000000000000000000000000000000000000000000000001f + 1000000000000000000000000000000000000000000000000000000000000200' + +# bytes3 +- types: ['bytes'] + args: ['0x10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000' ] + data: '0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000040 + 1000000000000000000000000000000000000000000000000000000000000000 + 1000000000000000000000000000000000000000000000000000000000000000' + +# two bytes +- types: ['bytes', 'bytes'] + args: ['0x10000000000000000000000000000000000000000000000000000000000002', + '0x0010000000000000000000000000000000000000000000000000000000000002'] + data: '0000000000000000000000000000000000000000000000000000000000000040 + 0000000000000000000000000000000000000000000000000000000000000080 + 000000000000000000000000000000000000000000000000000000000000001f + 1000000000000000000000000000000000000000000000000000000000000200 + 0000000000000000000000000000000000000000000000000000000000000020 + 0010000000000000000000000000000000000000000000000000000000000002' + +# fixed bytes +- types: ['bytes2'] + args: ['0x1234'] + data: '1234000000000000000000000000000000000000000000000000000000000000' + + +# dynamic array of bytes +- types: ['bytes[]'] + args: [['0x019c80031b20d5e69c8093a571162299032018d913930d93ab320ae5ea44a4218a274f00d607']] + data: '0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000001 + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000026 + 019c80031b20d5e69c8093a571162299032018d913930d93ab320ae5ea44a421 + 8a274f00d6070000000000000000000000000000000000000000000000000000' + +# dynamic array of bytes2 +- types: ['bytes[]'] + args: [['0x4444444444444444444444444444444444444444444444444444444444444444444444444444', + '0x6666666666666666666666666666666666666666666666666666666666666666666666666666']] + data: '0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000000000000000000000000000000000000000000040 + 00000000000000000000000000000000000000000000000000000000000000a0 + 0000000000000000000000000000000000000000000000000000000000000026 + 4444444444444444444444444444444444444444444444444444444444444444 + 4444444444440000000000000000000000000000000000000000000000000000 + 0000000000000000000000000000000000000000000000000000000000000026 + 6666666666666666666666666666666666666666666666666666666666666666 + 6666666666660000000000000000000000000000000000000000000000000000' + +# dynamic tuple of bytes2 +- types: ['(bytes,bytes)'] + args: [['0x4444444444444444444444444444444444444444444444444444444444444444444444444444', + '0x6666666666666666666666666666666666666666666666666666666666666666666666666666']] + data: '0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000040 + 00000000000000000000000000000000000000000000000000000000000000a0 + 0000000000000000000000000000000000000000000000000000000000000026 + 4444444444444444444444444444444444444444444444444444444444444444 + 4444444444440000000000000000000000000000000000000000000000000000 + 0000000000000000000000000000000000000000000000000000000000000026 + 6666666666666666666666666666666666666666666666666666666666666666 + 6666666666660000000000000000000000000000000000000000000000000000' + + +# uint +- types: ['uint256'] + args: [4] + data: '0000000000000000000000000000000000000000000000000000000000000004' + +# int +- types: ['int256'] + args: [4] + data: '0000000000000000000000000000000000000000000000000000000000000004' +