Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions micheline/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ const (
I_IS_IMPLICIT_ACCOUNT // 9E

// v24 additions
I_INDEX_ADDRESS // 9F
I_INDEX_ADDRESS // 9F
I_GET_ADDRESS_INDEX // A0
)

func (op OpCode) IsValid() bool {
return op <= I_INDEX_ADDRESS
return op <= I_GET_ADDRESS_INDEX
}

var (
Expand Down Expand Up @@ -375,6 +376,7 @@ var (
D_TICKET: "Ticket",
I_IS_IMPLICIT_ACCOUNT: "IS_IMPLICIT_ACCOUNT",
I_INDEX_ADDRESS: "INDEX_ADDRESS",
I_GET_ADDRESS_INDEX: "GET_ADDRESS_INDEX",
}
stringToOp map[string]OpCode
)
Expand Down
31 changes: 29 additions & 2 deletions micheline/opcodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func TestParseOpCode(t *testing.T) {
expected: I_INDEX_ADDRESS,
wantErr: false,
},
{
name: "GET_ADDRESS_INDEX",
input: "GET_ADDRESS_INDEX",
expected: I_GET_ADDRESS_INDEX,
wantErr: false,
},
// Positive case - new Seoul primitive
{
name: "IS_IMPLICIT_ACCOUNT",
Expand Down Expand Up @@ -129,6 +135,11 @@ func TestOpCodeString(t *testing.T) {
opcode: I_INDEX_ADDRESS,
expected: "INDEX_ADDRESS",
},
{
name: "GET_ADDRESS_INDEX string representation",
opcode: I_GET_ADDRESS_INDEX,
expected: "GET_ADDRESS_INDEX",
},
// Negative case - invalid opcode
{
name: "invalid opcode",
Expand Down Expand Up @@ -189,10 +200,15 @@ func TestOpCodeIsValid(t *testing.T) {
opcode: I_INDEX_ADDRESS,
expected: true,
},
{
name: "GET_ADDRESS_INDEX is valid",
opcode: I_GET_ADDRESS_INDEX,
expected: true,
},
// Negative cases - invalid opcodes
{
name: "opcode beyond INDEX_ADDRESS is invalid",
opcode: I_INDEX_ADDRESS + 1,
name: "opcode beyond GET_ADDRESS_INDEX is invalid",
opcode: I_GET_ADDRESS_INDEX + 1,
expected: false,
},
{
Expand Down Expand Up @@ -248,6 +264,11 @@ func TestOpCodeByte(t *testing.T) {
opcode: I_INDEX_ADDRESS,
expected: 0x9F, // 159 decimal
},
{
name: "GET_ADDRESS_INDEX byte value",
opcode: I_GET_ADDRESS_INDEX,
expected: 0xA0, // 160 decimal
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -285,6 +306,12 @@ func TestOpCodeMarshalText(t *testing.T) {
expected: "INDEX_ADDRESS",
wantErr: false,
},
{
name: "GET_ADDRESS_INDEX marshal text",
opcode: I_GET_ADDRESS_INDEX,
expected: "GET_ADDRESS_INDEX",
wantErr: false,
},
{
name: "invalid opcode marshal text",
opcode: OpCode(255),
Expand Down
10 changes: 10 additions & 0 deletions micheline/primitives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ func TestUnmarshalIndexAddress(t *testing.T) {
err = json.Unmarshal([]byte(`{"prim": "Index_Address"}`), &prim)
assert.NotNil(t, err)
}

func TestUnmarshalGetAddressIndex(t *testing.T) {
var prim Prim
err := json.Unmarshal([]byte(`{"prim": "GET_ADDRESS_INDEX"}`), &prim)
assert.Nil(t, err)
assert.Equal(t, I_GET_ADDRESS_INDEX, prim.OpCode)

err = json.Unmarshal([]byte(`{"prim": "Get_address_index"}`), &prim)
assert.NotNil(t, err)
}
Loading