diff --git a/typeConversion_test.go b/typeConversion_test.go index c3b764c..db5768d 100644 --- a/typeConversion_test.go +++ b/typeConversion_test.go @@ -536,61 +536,390 @@ func TestConvertArg_Special(t *testing.T) { compatibilityMode bool } tests := []Test{ + // ===== Option tests ===== { - strTag: "0x1::option::Option>>>", + strTag: "0x1::option::Option", arg: nil, - expected: []byte{0}, + expected: []byte{0}, // None }, { - strTag: "0x1::option::Option>>>", - arg: []any{[]any{[]any{}, []any{22}}, []any{}, []any{[]any{42}}}, - expected: []byte{1, 3, 2, 0, 1, 22, 0, 1, 1, 42}, + strTag: "0x1::option::Option", + arg: uint8(42), + expected: []byte{1, 42}, // Some(42) - native Go type }, { - strTag: "vector>>", - arg: []any{[]any{[]any{}, []any{false}}, []any{}, []any{[]any{true}}}, - expected: []byte{3, 2, 0, 1, 0, 0, 1, 1, 1}, + strTag: "0x1::option::Option", + arg: 255, + expected: []byte{1, 255}, // Some(255) - int as u8 }, { - strTag: "vector>>", - arg: []any{[]any{[]any{}, []any{22}}, []any{}, []any{[]any{42}}}, - expected: []byte{3, 2, 0, 1, 22, 0, 0, 1, 1, 0x2a, 0}, + strTag: "0x1::option::Option", + arg: "0", + expected: []byte{1, 0}, // Some(0) - string compatibility + compatibilityMode: true, }, { - strTag: "vector>>", - arg: []any{[]any{"0x4222"}, []any{}, []string{"0x32"}}, - expected: []byte{3, 1, 2, 0x42, 0x22, 0, 1, 1, 0x32}, + strTag: "0x1::option::Option", + arg: "255", + expected: []byte{1, 255}, // Some(255) - string compatibility + compatibilityMode: true, + }, + { + strTag: "0x1::option::Option", + arg: "42", + expected: []byte{1, 42}, + compatibilityMode: true, + }, + + // ===== Option tests ===== + { + strTag: "0x1::option::Option", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option", + arg: uint16(1000), + expected: []byte{1, 0xe8, 0x03}, // Some(1000) - native Go type + }, + { + strTag: "0x1::option::Option", + arg: "1000", + expected: []byte{1, 0xe8, 0x03}, + compatibilityMode: true, + }, + + // ===== Option tests ===== + { + strTag: "0x1::option::Option", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option", + arg: uint32(100000), + expected: []byte{1, 0xa0, 0x86, 0x01, 0x00}, // Some(100000) - native Go type + }, + { + strTag: "0x1::option::Option", + arg: "0", + expected: []byte{1, 0x00, 0x00, 0x00, 0x00}, // Some(0) - string compatibility + compatibilityMode: true, + }, + { + strTag: "0x1::option::Option", + arg: "100000", + expected: []byte{1, 0xa0, 0x86, 0x01, 0x00}, // Some(100000) - string compatibility + compatibilityMode: true, + }, + + // ===== Option tests ===== + { + strTag: "0x1::option::Option", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option", + arg: uint64(1000000000), + expected: []byte{1, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00}, // Some(1000000000) - native Go type + }, + { + strTag: "0x1::option::Option", + arg: "0", + expected: []byte{1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Some(0) - string compatibility + compatibilityMode: true, + }, + { + strTag: "0x1::option::Option", + arg: "123", + expected: []byte{1, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Some(123) - string compatibility + compatibilityMode: true, + }, + { + strTag: "0x1::option::Option", + arg: "1000000000", + expected: []byte{1, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00}, + compatibilityMode: true, + }, + + // ===== Option tests ===== + { + strTag: "0x1::option::Option", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option", + arg: "123456789", + expected: []byte{1, 0x15, 0xcd, 0x5b, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Some(123456789) - string works for u128 + }, + { + strTag: "0x1::option::Option", + arg: "0", + expected: []byte{1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Some(0) - string compatibility + compatibilityMode: true, + }, + { + strTag: "0x1::option::Option", + arg: "123456789", + expected: []byte{1, 0x15, 0xcd, 0x5b, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + compatibilityMode: true, + }, + + // ===== Option tests ===== + { + strTag: "0x1::option::Option", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option", + arg: "987654321", + expected: []byte{1, 0xb1, 0x68, 0xde, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Some(987654321) - string works for u256 + }, + { + strTag: "0x1::option::Option", + arg: "0", + expected: []byte{1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Some(0) - string compatibility + compatibilityMode: true, + }, + { + strTag: "0x1::option::Option", + arg: "987654321", + expected: []byte{1, 0xb1, 0x68, 0xde, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + compatibilityMode: true, + }, + + // ===== Option tests ===== + { + strTag: "0x1::option::Option", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option", + arg: true, + expected: []byte{1, 1}, // Some(true) - native Go type + }, + { + strTag: "0x1::option::Option", + arg: false, + expected: []byte{1, 0}, // Some(false) - native Go type + }, + { + strTag: "0x1::option::Option", + arg: "true", + expected: []byte{1, 1}, + compatibilityMode: true, + }, + { + strTag: "0x1::option::Option", + arg: "false", + expected: []byte{1, 0}, + compatibilityMode: true, + }, + + // ===== Option
tests ===== + { + strTag: "0x1::option::Option
", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option
", + arg: AccountOne, + expected: []byte{1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, // Some(0x1) + }, + { + strTag: "0x1::option::Option
", + arg: "0x0", + expected: []byte{1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Some(0x0) + }, + { + strTag: "0x1::option::Option
", + arg: "0x1", + expected: []byte{1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, // Some(0x1) }, - { // Special case, difference in behavior with compatibility mode + { + strTag: "0x1::option::Option
", + arg: "0x00", + expected: []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + compatibilityMode: true, + }, + + // ===== Option tests ===== + { strTag: "0x1::option::Option", arg: "0x00", expected: []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, compatibilityMode: false, }, - { // Special case in compatibility mode + { strTag: "0x1::option::Option", - arg: "0x00", - expected: []byte{0}, - compatibilityMode: true, + arg: "0x01", + expected: []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, + compatibilityMode: false, + }, + + // ===== Option tests ===== + { + strTag: "0x1::option::Option<0x1::string::String>", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option<0x1::string::String>", + arg: "", + expected: []byte{1, 0}, // Some("") + }, + { + strTag: "0x1::option::Option<0x1::string::String>", + arg: "hello", + expected: []byte{1, 5, 0x68, 0x65, 0x6c, 0x6c, 0x6f}, // Some("hello") + }, + + // ===== Option tests ===== + { + strTag: "0x1::option::Option<0x1::object::Object<0x1::aptos_coin::AptosCoin>>", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option<0x1::object::Object<0x1::aptos_coin::AptosCoin>>", + arg: "0x0", + expected: []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Some(0x0) + }, + { + strTag: "0x1::option::Option<0x1::object::Object<0x1::aptos_coin::AptosCoin>>", + arg: "0x1", + expected: []byte{1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, // Some(0x1) + }, + { + strTag: "0x1::option::Option<0x1::object::Object<0x1::string::String>>", + arg: "0xabcdef1234567890abcdef1234567890abcdef12", + expected: []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12}, // Some(long address) + }, + + // ===== Option> tests ===== + { + strTag: "0x1::option::Option>", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option>", + arg: "", + expected: []byte{1, 0}, // Some([]) }, - { // Special case in compatibility mode + { + strTag: "0x1::option::Option>", + arg: []byte{}, + expected: []byte{1, 0}, // Some([]) - empty vector as []byte + }, + { + strTag: "0x1::option::Option>", + arg: "0x1234", + expected: []byte{1, 2, 0x12, 0x34}, // Some([0x12, 0x34]) + }, + { + strTag: "0x1::option::Option>", + arg: []byte{0x12, 0x34}, + expected: []byte{1, 2, 0x12, 0x34}, // Some([0x12, 0x34]) + }, + { strTag: "0x1::option::Option>", arg: "0x00", - expected: []byte{0}, + expected: []byte{1, 4, 48, 120, 48, 48}, compatibilityMode: true, }, - { // Special case in compatibility mode + { strTag: "0x1::option::Option>", - arg: "0x0100", - expected: []byte{1, 0}, + arg: "0x0102", + expected: []byte{1, 6, 48, 120, 48, 49, 48, 50}, compatibilityMode: true, }, - { // Special case in compatibility mode + { strTag: "0x1::option::Option>", - arg: "0x010102", - expected: []byte{1, 1, 2}, + arg: "0x1234", + expected: []byte{1, 6, 48, 120, 49, 50, 51, 52}, compatibilityMode: true, }, + + // ===== Option> tests ===== + { + strTag: "0x1::option::Option>", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option>", + arg: []string{}, + expected: []byte{1, 0}, // Some([]) + }, + { + strTag: "0x1::option::Option>", + arg: []string{"0x0"}, + expected: []byte{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Some([0x0]) + }, + { + strTag: "0x1::option::Option>", + arg: []string{"0x1", "0x2"}, + expected: []byte{1, 2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, // Some([0x1, 0x2]) + }, + + // ===== Option> tests ===== + { + strTag: "0x1::option::Option>", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option>", + arg: []string{}, + expected: []byte{1, 0}, // Some([]) + }, + { + strTag: "0x1::option::Option>", + arg: []string{""}, + expected: []byte{1, 1, 0}, // Some([""]) - vector with one empty string + }, + { + strTag: "0x1::option::Option>", + arg: []string{"hello", "world"}, + expected: []byte{1, 2, 5, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 5, 0x77, 0x6f, 0x72, 0x6c, 0x64}, // Some(["hello", "world"]) + }, + + // ===== Option> tests ===== + { + strTag: "0x1::option::Option>>", + arg: nil, + expected: []byte{0}, // None + }, + { + strTag: "0x1::option::Option>>", + arg: []string{}, + expected: []byte{1, 0}, // Some([]) + }, + { + strTag: "0x1::option::Option>>", + arg: []string{"0x1", "0x2"}, + expected: []byte{1, 2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, // Some([0x1, 0x2]) + }, + + // ===== Option tests ===== + { + strTag: "0x1::option::Option>>>", + arg: nil, + expected: []byte{0}, + }, + { + strTag: "0x1::option::Option>>>", + arg: []any{[]any{[]any{}, []any{22}}, []any{}, []any{[]any{42}}}, + expected: []byte{1, 3, 2, 0, 1, 22, 0, 1, 1, 42}, + }, + + // ===== vector tests (non-option) ===== { strTag: "vector", arg: "0x00", @@ -603,6 +932,21 @@ func TestConvertArg_Special(t *testing.T) { expected: []byte{4, 0x30, 0x78, 0x30, 0x30}, compatibilityMode: true, }, + { + strTag: "vector>>", + arg: []any{[]any{[]any{}, []any{false}}, []any{}, []any{[]any{true}}}, + expected: []byte{3, 2, 0, 1, 0, 0, 1, 1, 1}, + }, + { + strTag: "vector>>", + arg: []any{[]any{[]any{}, []any{22}}, []any{}, []any{[]any{42}}}, + expected: []byte{3, 2, 0, 1, 22, 0, 0, 1, 1, 0x2a, 0}, + }, + { + strTag: "vector>>", + arg: []any{[]any{"0x4222"}, []any{}, []string{"0x32"}}, + expected: []byte{3, 1, 2, 0x42, 0x22, 0, 1, 1, 0x32}, + }, } for _, tt := range tests {