Merge pull request #1 from status-im/fix-bytes-n

Fix selector for larger byte arrays
This commit is contained in:
markspanbroek 2022-04-07 15:35:24 +02:00 committed by GitHub
commit fd377e59da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 4 deletions

View File

@ -1 +0,0 @@
nim 1.6.0

View File

@ -11,7 +11,7 @@ Use the [Nimble][2] package manager to add `contractabi` to an existing project.
Add the following to its .nimble file:
```nim
requires "contractabi >= 0.4.2 & < 0.5.0"
requires "contractabi >= 0.4.3 & < 0.5.0"
```
Usage

View File

@ -1,4 +1,4 @@
version = "0.4.2"
version = "0.4.3"
author = "Contract ABI Authors"
description = "ABI Encoding for Ethereum contracts"
license = "MIT"

View File

@ -40,7 +40,10 @@ solidityType Address, "address"
func solidityType*[N: static int, T](_: type array[N, T]): string =
when T is byte:
"bytes" & $N
when 0 < N and N <= 32:
"bytes" & $N
else:
"bytes1[" & $N & "]"
else:
solidityType(T) & "[" & $N & "]"

View File

@ -22,6 +22,9 @@ suite "function selector":
check solidityType(Address) == "address"
check solidityType(array[4, byte]) == "bytes4"
check solidityType(array[16, byte]) == "bytes16"
check solidityType(array[32, byte]) == "bytes32"
check solidityType(array[0, byte]) == "bytes1[0]"
check solidityType(array[33, byte]) == "bytes1[33]"
check solidityType(seq[byte]) == "bytes"
check solidityType(array[4, string]) == "string[4]"
check solidityType(seq[string]) == "string[]"