summaryrefslogtreecommitdiff
path: root/data/abi/abi_type_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'data/abi/abi_type_test.go')
-rw-r--r--data/abi/abi_type_test.go164
1 files changed, 82 insertions, 82 deletions
diff --git a/data/abi/abi_type_test.go b/data/abi/abi_type_test.go
index 136ecb8cf..f96dfaf06 100644
--- a/data/abi/abi_type_test.go
+++ b/data/abi/abi_type_test.go
@@ -32,21 +32,21 @@ func TestMakeTypeValid(t *testing.T) {
partitiontest.PartitionTest(t)
// uint
for i := 8; i <= 512; i += 8 {
- uintType, err := MakeUintType(uint16(i))
+ uintType, err := makeUintType(i)
require.NoError(t, err, "make uint type in valid space should not return error")
expected := "uint" + strconv.Itoa(i)
actual := uintType.String()
- require.Equal(t, expected, actual, "MakeUintType: expected %s, actual %s", expected, actual)
+ require.Equal(t, expected, actual, "makeUintType: expected %s, actual %s", expected, actual)
}
// ufixed
for i := 8; i <= 512; i += 8 {
for j := 1; j <= 160; j++ {
- ufixedType, err := MakeUfixedType(uint16(i), uint16(j))
+ ufixedType, err := makeUfixedType(i, j)
require.NoError(t, err, "make ufixed type in valid space should not return error")
expected := "ufixed" + strconv.Itoa(i) + "x" + strconv.Itoa(j)
actual := ufixedType.String()
require.Equal(t, expected, actual,
- "TypeFromString ufixed error: expected %s, actual %s", expected, actual)
+ "TypeOf ufixed error: expected %s, actual %s", expected, actual)
}
}
// bool/strings/address/byte + dynamic/static array + tuple
@@ -55,13 +55,13 @@ func TestMakeTypeValid(t *testing.T) {
testType string
expected string
}{
- {input: MakeBoolType(), testType: "bool", expected: "bool"},
- {input: MakeStringType(), testType: "string", expected: "string"},
- {input: MakeAddressType(), testType: "address", expected: "address"},
- {input: MakeByteType(), testType: "byte", expected: "byte"},
+ {input: boolType, testType: "bool", expected: "bool"},
+ {input: stringType, testType: "string", expected: "string"},
+ {input: addressType, testType: "address", expected: "address"},
+ {input: byteType, testType: "byte", expected: "byte"},
// dynamic array
{
- input: MakeDynamicArrayType(
+ input: makeDynamicArrayType(
Type{
abiTypeID: Uint,
bitSize: uint16(32),
@@ -71,16 +71,16 @@ func TestMakeTypeValid(t *testing.T) {
expected: "uint32[]",
},
{
- input: MakeDynamicArrayType(
- MakeDynamicArrayType(
- MakeByteType(),
+ input: makeDynamicArrayType(
+ makeDynamicArrayType(
+ byteType,
),
),
testType: "dynamic array",
expected: "byte[][]",
},
{
- input: MakeStaticArrayType(
+ input: makeStaticArrayType(
Type{
abiTypeID: Ufixed,
bitSize: uint16(128),
@@ -92,9 +92,9 @@ func TestMakeTypeValid(t *testing.T) {
expected: "ufixed128x10[100]",
},
{
- input: MakeStaticArrayType(
- MakeStaticArrayType(
- MakeBoolType(),
+ input: makeStaticArrayType(
+ makeStaticArrayType(
+ boolType,
uint16(128),
),
uint16(256),
@@ -114,10 +114,10 @@ func TestMakeTypeValid(t *testing.T) {
{
abiTypeID: Tuple,
childTypes: []Type{
- MakeAddressType(),
- MakeByteType(),
- MakeStaticArrayType(MakeBoolType(), uint16(10)),
- MakeDynamicArrayType(
+ addressType,
+ byteType,
+ makeStaticArrayType(boolType, uint16(10)),
+ makeDynamicArrayType(
Type{
abiTypeID: Ufixed,
bitSize: uint16(256),
@@ -127,7 +127,7 @@ func TestMakeTypeValid(t *testing.T) {
},
staticLength: 4,
},
- MakeDynamicArrayType(MakeByteType()),
+ makeDynamicArrayType(byteType),
},
staticLength: 3,
},
@@ -153,8 +153,8 @@ func TestMakeTypeInvalid(t *testing.T) {
randInput = rand.Uint32() % (1 << 16)
}
// note: if a var mod 8 = 0 (or not) in uint32, then it should mod 8 = 0 (or not) in uint16.
- _, err := MakeUintType(uint16(randInput))
- require.Error(t, err, "MakeUintType: should throw error on bitSize input %d", uint16(randInput))
+ _, err := makeUintType(int(randInput))
+ require.Error(t, err, "makeUintType: should throw error on bitSize input %d", uint16(randInput))
}
// ufixed
for i := 0; i <= 10000; i++ {
@@ -166,8 +166,8 @@ func TestMakeTypeInvalid(t *testing.T) {
for randPrecision >= 1 && randPrecision <= 160 {
randPrecision = rand.Uint32()
}
- _, err := MakeUfixedType(uint16(randSize), uint16(randPrecision))
- require.Error(t, err, "MakeUfixedType: should throw error on bitSize %d, precision %d", randSize, randPrecision)
+ _, err := makeUfixedType(int(randSize), int(randPrecision))
+ require.Error(t, err, "makeUfixedType: should throw error on bitSize %d, precision %d", randSize, randPrecision)
}
}
@@ -175,22 +175,22 @@ func TestTypeFromStringValid(t *testing.T) {
partitiontest.PartitionTest(t)
// uint
for i := 8; i <= 512; i += 8 {
- expected, err := MakeUintType(uint16(i))
+ expected, err := makeUintType(i)
require.NoError(t, err, "make uint type in valid space should not return error")
- actual, err := TypeFromString(expected.String())
- require.NoError(t, err, "TypeFromString: uint parsing error: %s", expected.String())
+ actual, err := TypeOf(expected.String())
+ require.NoError(t, err, "TypeOf: uint parsing error: %s", expected.String())
require.Equal(t, expected, actual,
- "TypeFromString: expected %s, actual %s", expected.String(), actual.String())
+ "TypeOf: expected %s, actual %s", expected.String(), actual.String())
}
// ufixed
for i := 8; i <= 512; i += 8 {
for j := 1; j <= 160; j++ {
- expected, err := MakeUfixedType(uint16(i), uint16(j))
+ expected, err := makeUfixedType(i, j)
require.NoError(t, err, "make ufixed type in valid space should not return error")
- actual, err := TypeFromString("ufixed" + strconv.Itoa(i) + "x" + strconv.Itoa(j))
- require.NoError(t, err, "TypeFromString ufixed parsing error: %s", expected.String())
+ actual, err := TypeOf("ufixed" + strconv.Itoa(i) + "x" + strconv.Itoa(j))
+ require.NoError(t, err, "TypeOf ufixed parsing error: %s", expected.String())
require.Equal(t, expected, actual,
- "TypeFromString ufixed: expected %s, actual %s", expected.String(), actual.String())
+ "TypeOf ufixed: expected %s, actual %s", expected.String(), actual.String())
}
}
var testcases = []struct {
@@ -198,19 +198,19 @@ func TestTypeFromStringValid(t *testing.T) {
testType string
expected Type
}{
- {input: MakeBoolType().String(), testType: "bool", expected: MakeBoolType()},
- {input: MakeStringType().String(), testType: "string", expected: MakeStringType()},
- {input: MakeAddressType().String(), testType: "address", expected: MakeAddressType()},
- {input: MakeByteType().String(), testType: "byte", expected: MakeByteType()},
+ {input: boolType.String(), testType: "bool", expected: boolType},
+ {input: stringType.String(), testType: "string", expected: stringType},
+ {input: addressType.String(), testType: "address", expected: addressType},
+ {input: byteType.String(), testType: "byte", expected: byteType},
{
input: "uint256[]",
testType: "dynamic array",
- expected: MakeDynamicArrayType(Type{abiTypeID: Uint, bitSize: 256}),
+ expected: makeDynamicArrayType(Type{abiTypeID: Uint, bitSize: 256}),
},
{
input: "ufixed256x64[]",
testType: "dynamic array",
- expected: MakeDynamicArrayType(
+ expected: makeDynamicArrayType(
Type{
abiTypeID: Ufixed,
bitSize: 256,
@@ -221,11 +221,11 @@ func TestTypeFromStringValid(t *testing.T) {
{
input: "byte[][][][]",
testType: "dynamic array",
- expected: MakeDynamicArrayType(
- MakeDynamicArrayType(
- MakeDynamicArrayType(
- MakeDynamicArrayType(
- MakeByteType(),
+ expected: makeDynamicArrayType(
+ makeDynamicArrayType(
+ makeDynamicArrayType(
+ makeDynamicArrayType(
+ byteType,
),
),
),
@@ -235,16 +235,16 @@ func TestTypeFromStringValid(t *testing.T) {
{
input: "address[100]",
testType: "static array",
- expected: MakeStaticArrayType(
- MakeAddressType(),
+ expected: makeStaticArrayType(
+ addressType,
uint16(100),
),
},
{
input: "uint64[][200]",
testType: "static array",
- expected: MakeStaticArrayType(
- MakeDynamicArrayType(
+ expected: makeStaticArrayType(
+ makeDynamicArrayType(
Type{abiTypeID: Uint, bitSize: uint16(64)},
),
uint16(200),
@@ -273,10 +273,10 @@ func TestTypeFromStringValid(t *testing.T) {
{
abiTypeID: Tuple,
childTypes: []Type{
- MakeAddressType(),
- MakeByteType(),
- MakeStaticArrayType(MakeBoolType(), uint16(10)),
- MakeDynamicArrayType(
+ addressType,
+ byteType,
+ makeStaticArrayType(boolType, uint16(10)),
+ makeDynamicArrayType(
Type{
abiTypeID: Ufixed,
bitSize: uint16(256),
@@ -286,7 +286,7 @@ func TestTypeFromStringValid(t *testing.T) {
},
staticLength: 4,
},
- MakeDynamicArrayType(MakeByteType()),
+ makeDynamicArrayType(byteType),
},
staticLength: 3,
},
@@ -304,13 +304,13 @@ func TestTypeFromStringValid(t *testing.T) {
{
abiTypeID: Tuple,
childTypes: []Type{
- MakeAddressType(),
- MakeByteType(),
- MakeStaticArrayType(MakeBoolType(), uint16(10)),
+ addressType,
+ byteType,
+ makeStaticArrayType(boolType, uint16(10)),
{
abiTypeID: Tuple,
childTypes: []Type{
- MakeDynamicArrayType(
+ makeDynamicArrayType(
Type{
abiTypeID: Ufixed,
bitSize: uint16(256),
@@ -346,13 +346,13 @@ func TestTypeFromStringValid(t *testing.T) {
{
abiTypeID: Tuple,
childTypes: []Type{
- MakeAddressType(),
+ addressType,
{
abiTypeID: Tuple,
childTypes: []Type{
- MakeByteType(),
- MakeStaticArrayType(MakeBoolType(), uint16(10)),
- MakeDynamicArrayType(
+ byteType,
+ makeStaticArrayType(boolType, uint16(10)),
+ makeDynamicArrayType(
Type{
abiTypeID: Ufixed,
bitSize: uint16(256),
@@ -371,9 +371,9 @@ func TestTypeFromStringValid(t *testing.T) {
},
}
for _, testcase := range testcases {
- t.Run(fmt.Sprintf("TypeFromString test %s", testcase.testType), func(t *testing.T) {
- actual, err := TypeFromString(testcase.input)
- require.NoError(t, err, "TypeFromString %s parsing error", testcase.testType)
+ t.Run(fmt.Sprintf("TypeOf test %s", testcase.testType), func(t *testing.T) {
+ actual, err := TypeOf(testcase.input)
+ require.NoError(t, err, "TypeOf %s parsing error", testcase.testType)
require.Equal(t, testcase.expected, actual, "TestFromString %s: expected %s, actual %s",
testcase.testType, testcase.expected.String(), actual.String())
})
@@ -388,8 +388,8 @@ func TestTypeFromStringInvalid(t *testing.T) {
randSize = rand.Uint64()
}
errorInput := "uint" + strconv.FormatUint(randSize, 10)
- _, err := TypeFromString(errorInput)
- require.Error(t, err, "MakeUintType: should throw error on bitSize input %d", randSize)
+ _, err := TypeOf(errorInput)
+ require.Error(t, err, "makeUintType: should throw error on bitSize input %d", randSize)
}
for i := 0; i <= 10000; i++ {
randSize := rand.Uint64()
@@ -401,8 +401,8 @@ func TestTypeFromStringInvalid(t *testing.T) {
randPrecision = rand.Uint64()
}
errorInput := "ufixed" + strconv.FormatUint(randSize, 10) + "x" + strconv.FormatUint(randPrecision, 10)
- _, err := TypeFromString(errorInput)
- require.Error(t, err, "MakeUintType: should throw error on bitSize input %d", randSize)
+ _, err := TypeOf(errorInput)
+ require.Error(t, err, "makeUintType: should throw error on bitSize input %d", randSize)
}
var testcases = []string{
// uint
@@ -442,8 +442,8 @@ func TestTypeFromStringInvalid(t *testing.T) {
"((byte),,(byte))",
}
for _, testcase := range testcases {
- t.Run(fmt.Sprintf("TypeFromString dynamic array test %s", testcase), func(t *testing.T) {
- _, err := TypeFromString(testcase)
+ t.Run(fmt.Sprintf("TypeOf dynamic array test %s", testcase), func(t *testing.T) {
+ _, err := TypeOf(testcase)
require.Error(t, err, "%s should throw error", testcase)
})
}
@@ -474,27 +474,27 @@ func TestTypeMISC(t *testing.T) {
rand.Seed(time.Now().Unix())
var testpool = []Type{
- MakeBoolType(),
- MakeAddressType(),
- MakeStringType(),
- MakeByteType(),
+ boolType,
+ addressType,
+ stringType,
+ byteType,
}
for i := 8; i <= 512; i += 8 {
- uintT, err := MakeUintType(uint16(i))
+ uintT, err := makeUintType(i)
require.NoError(t, err, "make uint type error")
testpool = append(testpool, uintT)
}
for i := 8; i <= 512; i += 8 {
for j := 1; j <= 160; j++ {
- ufixedT, err := MakeUfixedType(uint16(i), uint16(j))
+ ufixedT, err := makeUfixedType(i, j)
require.NoError(t, err, "make ufixed type error: bitSize %d, precision %d", i, j)
testpool = append(testpool, ufixedT)
}
}
for _, testcase := range testpool {
- testpool = append(testpool, MakeDynamicArrayType(testcase))
- testpool = append(testpool, MakeStaticArrayType(testcase, 10))
- testpool = append(testpool, MakeStaticArrayType(testcase, 20))
+ testpool = append(testpool, makeDynamicArrayType(testcase))
+ testpool = append(testpool, makeStaticArrayType(testcase, 10))
+ testpool = append(testpool, makeStaticArrayType(testcase, 20))
}
for _, testcase := range testpool {
@@ -545,13 +545,13 @@ func TestTypeMISC(t *testing.T) {
isDynamicCount++
}
- addressByteLen, err := MakeAddressType().ByteLen()
+ addressByteLen, err := addressType.ByteLen()
require.NoError(t, err, "address type bytelen should not return error")
require.Equal(t, 32, addressByteLen, "address type bytelen should be 32")
- byteByteLen, err := MakeByteType().ByteLen()
+ byteByteLen, err := byteType.ByteLen()
require.NoError(t, err, "byte type bytelen should not return error")
require.Equal(t, 1, byteByteLen, "byte type bytelen should be 1")
- boolByteLen, err := MakeBoolType().ByteLen()
+ boolByteLen, err := boolType.ByteLen()
require.NoError(t, err, "bool type bytelen should be 1")
require.Equal(t, 1, boolByteLen, "bool type bytelen should be 1")