Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Jan 7, 2023
1 parent 1138804 commit feb41ee
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 360 deletions.
12 changes: 12 additions & 0 deletions abicoder/test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def hexdigest() self.unpack('H*').first; end
end

def hex( hex ) # convert hex(adecimal) string to binary string
## note: strip all whitespaces
hex = hex.gsub( /[ \t\n\r]/, '' )

if ['0x', '0X'].include?( hex[0,2] ) ## cut-of leading 0x or 0X if present
[hex[2..-1]].pack('H*')
else
Expand All @@ -19,6 +22,15 @@ def hex( hex ) # convert hex(adecimal) string to binary string
end


require 'yaml'

def read_yml( path )
txt = File.open( path, 'r:utf-8' ) { |f| f.read }
YAML.load( txt )
end




## our own code
require 'abicoder'
2 changes: 1 addition & 1 deletion abicoder/test/test_abi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def encode_int8( arg ) encode_int( arg, 8 ); end
def encode_bytes( arg, length=nil ) ABI.encoder.encode_bytes( arg, length ); end
def encode_address( arg ) ABI.encoder.encode_address( arg ); end

BYTE_ZERO = "\x00".b
BYTE_ZERO = "\x00".b.freeze

def zpad( bin ) ## note: same as builtin String#rjust !!!
l=32
Expand Down
74 changes: 0 additions & 74 deletions abicoder/test/test_basic_abi.rb

This file was deleted.

151 changes: 0 additions & 151 deletions abicoder/test/test_coder.rb

This file was deleted.

76 changes: 0 additions & 76 deletions abicoder/test/test_encoding.rb

This file was deleted.

51 changes: 51 additions & 0 deletions abicoder/test/test_fixtures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
##
# to run use
# ruby -I ./lib -I ./test test/test_fixtures.rb


require 'helper'




class TestFixtures < MiniTest::Test

def assert_bin( exp, bin ) ## note: always check for BINARY encoding too
assert bin.encoding == Encoding::BINARY
assert_equal exp, bin
end



def test_basic

tests = read_yml( '../test/abicoder/basic.yml' )
puts " #{tests.size} test(s) in /test/abicoder/basic.yml"
pp tests

tests.each do |test|
types = test['types']
args = test['args']
hex = test['data']

=begin
## quick hack for bytes / bytes10 etc.
## change encoding to BINARAY / ASCII_8BIT
## not really possible with yaml fixtures
args = types.zip(args).map do |(type,arg)|
arg = arg.b if ['bytes', 'bytes10'].include?( type )
arg
end
=end
if hex
data = hex( hex ) ## convert hex string to binary string
assert_bin data, ABI.encode( types, args )
assert_equal args, ABI.decode( types, data )
end
assert_equal args, ABI.decode( types, ABI.encode( types, args ))
end
end


end ## class TestFixtures

Loading

0 comments on commit feb41ee

Please sign in to comment.