Skip to content

Commit f145b22

Browse files
Fix: handle DAMode
1 parent 02f2af9 commit f145b22

File tree

4 files changed

+212
-6
lines changed

4 files changed

+212
-6
lines changed

pkg/data/da_mode.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package data
2+
3+
// swagger:enum DAMode
4+
/*
5+
ENUM(
6+
L1,
7+
L2
8+
)
9+
*/
10+
//go:generate go-enum --marshal --sql --values
11+
type DAMode string

pkg/data/da_mode_enum.go

Lines changed: 136 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/data/da_mode_enum_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package data
2+
3+
import (
4+
"testing"
5+
6+
"github.com/goccy/go-json"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestDAMode_UnmarshalJSON(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
want DAMode
14+
text []byte
15+
wantErr bool
16+
}{
17+
{
18+
name: "test 1",
19+
want: DAModeL1,
20+
text: []byte(`{"mode":0}`),
21+
}, {
22+
name: "test 2",
23+
want: DAModeL2,
24+
text: []byte(`{"mode":1}`),
25+
}, {
26+
name: "test 3",
27+
want: DAModeL1,
28+
text: []byte(`{"mode":"L1"}`),
29+
}, {
30+
name: "test 4",
31+
want: DAModeL2,
32+
text: []byte(`{"mode":"L2"}`),
33+
}, {
34+
name: "test 5",
35+
text: []byte(`{"mode":10}`),
36+
wantErr: true,
37+
}, {
38+
name: "test 6",
39+
text: []byte(`{"mode":"10"}`),
40+
wantErr: true,
41+
},
42+
}
43+
for _, tt := range tests {
44+
t.Run(tt.name, func(t *testing.T) {
45+
type buf struct {
46+
Mode DAMode `json:"mode"`
47+
}
48+
var x buf
49+
err := json.Unmarshal(tt.text, &x)
50+
51+
if tt.wantErr {
52+
require.Error(t, err)
53+
} else {
54+
require.NoError(t, err)
55+
require.Equal(t, tt.want, x.Mode)
56+
}
57+
})
58+
}
59+
}

pkg/data/transaction.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ type Invoke struct {
1313
EntrypointSelector Felt `json:"entry_point_selector"`
1414
SenderAddress Felt `json:"sender_address"`
1515
ChainId Felt `json:"chain_id"`
16-
FeeDataAvailabilityMode uint64 `json:"fee_data_availability_mode"`
17-
NonceDataAvailabilityMode uint64 `json:"nonce_data_availability_mode"`
16+
FeeDataAvailabilityMode DAMode `json:"fee_data_availability_mode"`
17+
NonceDataAvailabilityMode DAMode `json:"nonce_data_availability_mode"`
1818
ResourceBounds *ResourceBounds `json:"resource_bounds,omitempty"`
1919
Tip Felt `json:"tip"`
2020
Signature []string `json:"signature"`
@@ -71,8 +71,8 @@ type Declare struct {
7171
CompiledClassHash Felt `json:"compiled_class_hash,omitempty"`
7272
AccountDeploymentData []Felt `json:"account_deployment_data"`
7373
ChainId Felt `json:"chain_id"`
74-
FeeDataAvailabilityMode uint64 `json:"fee_data_availability_mode"`
75-
NonceDataAvailabilityMode uint64 `json:"nonce_data_availability_mode"`
74+
FeeDataAvailabilityMode DAMode `json:"fee_data_availability_mode"`
75+
NonceDataAvailabilityMode DAMode `json:"nonce_data_availability_mode"`
7676
PayMasterData []Felt `json:"paymaster_data"`
7777
Tip Felt `json:"tip"`
7878
}
@@ -132,8 +132,8 @@ type DeployAccount struct {
132132
ConstructorCalldata []string `json:"constructor_calldata"`
133133
Signature []string `json:"signature"`
134134
ChainId Felt `json:"chain_id"`
135-
FeeDataAvailabilityMode uint64 `json:"fee_data_availability_mode"`
136-
NonceDataAvailabilityMode uint64 `json:"nonce_data_availability_mode"`
135+
FeeDataAvailabilityMode DAMode `json:"fee_data_availability_mode"`
136+
NonceDataAvailabilityMode DAMode `json:"nonce_data_availability_mode"`
137137
PayMasterData []Felt `json:"paymaster_data"`
138138
Tip Felt `json:"tip"`
139139
}

0 commit comments

Comments
 (0)