Skip to content

Commit 7c9a3f2

Browse files
Enum parsing
1 parent e9a699e commit 7c9a3f2

File tree

2 files changed

+133
-1
lines changed

2 files changed

+133
-1
lines changed

pkg/abi/decode.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ func decodeItem(calldata []string, input Type, structs map[string]*StructItem, e
161161
return nil, err
162162
}
163163
if int(enumIdx) > len(enum.Variants)-1 {
164-
return nil, errors.Errorf("too big enum index: %d", enumIdx)
164+
result[input.Name] = calldata[0]
165+
return calldata[1:], nil
165166
}
166167
variant := enum.Variants[enumIdx]
167168

pkg/abi/decode_test.go

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,137 @@ func TestDecodeFunctionCallData(t *testing.T) {
925925
},
926926
"min_liquidity": "5937915978828",
927927
},
928+
}, {
929+
name: "test 13: too big enum value",
930+
args: args{
931+
calldata: []string{
932+
"0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
933+
"0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
934+
"0x20c49ba5e353f80000000000000000",
935+
"0x3e8",
936+
"0x0",
937+
"0x132bb70",
938+
"0x3",
939+
"0x12fae30",
940+
"0x1",
941+
"0x566875f644c",
942+
},
943+
endpoint: "mint_and_deposit",
944+
abi: `[
945+
{
946+
"name": "core::bool",
947+
"type": "enum",
948+
"variants": [
949+
{
950+
"name": "False",
951+
"type": "()"
952+
},
953+
{
954+
"name": "True",
955+
"type": "()"
956+
}
957+
]
958+
},
959+
{
960+
"name": "ekubo::types::i129::i129",
961+
"type": "struct",
962+
"members": [
963+
{
964+
"name": "mag",
965+
"type": "core::integer::u128"
966+
},
967+
{
968+
"name": "sign",
969+
"type": "core::bool"
970+
}
971+
]
972+
},
973+
{
974+
"name": "ekubo::types::bounds::Bounds",
975+
"type": "struct",
976+
"members": [
977+
{
978+
"name": "lower",
979+
"type": "ekubo::types::i129::i129"
980+
},
981+
{
982+
"name": "upper",
983+
"type": "ekubo::types::i129::i129"
984+
}
985+
]
986+
},
987+
{
988+
"name": "ekubo::types::keys::PoolKey",
989+
"type": "struct",
990+
"members": [
991+
{
992+
"name": "token0",
993+
"type": "core::starknet::contract_address::ContractAddress"
994+
},
995+
{
996+
"name": "token1",
997+
"type": "core::starknet::contract_address::ContractAddress"
998+
},
999+
{
1000+
"name": "fee",
1001+
"type": "core::integer::u128"
1002+
},
1003+
{
1004+
"name": "tick_spacing",
1005+
"type": "core::integer::u128"
1006+
},
1007+
{
1008+
"name": "extension",
1009+
"type": "core::starknet::contract_address::ContractAddress"
1010+
}
1011+
]
1012+
},
1013+
{
1014+
"name": "mint_and_deposit",
1015+
"type": "function",
1016+
"inputs": [
1017+
{
1018+
"name": "pool_key",
1019+
"type": "ekubo::types::keys::PoolKey"
1020+
},
1021+
{
1022+
"name": "bounds",
1023+
"type": "ekubo::types::bounds::Bounds"
1024+
},
1025+
{
1026+
"name": "min_liquidity",
1027+
"type": "core::integer::u128"
1028+
}
1029+
],
1030+
"outputs": [
1031+
{
1032+
"type": "(core::integer::u64, core::integer::u128)"
1033+
}
1034+
],
1035+
"state_mutability": "external"
1036+
}
1037+
]`,
1038+
},
1039+
want: map[string]any{
1040+
"pool_key": map[string]any{
1041+
"token0": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
1042+
"token1": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
1043+
"fee": "170141183460469235273462165868118016",
1044+
"tick_spacing": "1000",
1045+
"extension": "0x0",
1046+
},
1047+
"bounds": map[string]any{
1048+
"lower": map[string]any{
1049+
"mag": "20102000",
1050+
"sign": "0x3",
1051+
},
1052+
"upper": map[string]any{
1053+
"mag": "19902000",
1054+
"sign": "True",
1055+
},
1056+
},
1057+
"min_liquidity": "5937915978828",
1058+
},
9281059
},
9291060
}
9301061
for _, tt := range tests {

0 commit comments

Comments
 (0)