Skip to content

Commit

Permalink
up abi tests
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Jan 8, 2023
1 parent 093b220 commit 77c56b3
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 11 deletions.
2 changes: 1 addition & 1 deletion abicoder/lib/abicoder/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module ABICoder
MAJOR = 1
MINOR = 0
PATCH = 0
PATCH = 1
VERSION = [MAJOR,MINOR,PATCH].join('.')

def self.version
Expand Down
21 changes: 20 additions & 1 deletion abicoder/test/test_fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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
Expand Down
134 changes: 125 additions & 9 deletions test/abicoder/more.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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[]' ]
Expand Down Expand Up @@ -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'

0 comments on commit 77c56b3

Please sign in to comment.