Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil committed Jan 31, 2025
1 parent ee0a9a3 commit 8617b5c
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions rpc/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1358,3 +1358,88 @@ func TestTransactionStatus(t *testing.T) {
})
}
}

func TestResourceMarshalText(t *testing.T) {
tests := []struct {
name string
resource rpc.Resource
want []byte
err bool
}{
{
name: "l1 gas",
resource: rpc.ResourceL1Gas,
want: []byte("l1_gas"),
},
{
name: "l2 gas",
resource: rpc.ResourceL2Gas,
want: []byte("l2_gas"),
},
{
name: "l1 data gas",
resource: rpc.ResourceL1DataGas,
want: []byte("l1_data_gas"),
},
{
name: "error",
resource: rpc.Resource(0),
err: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.resource.MarshalText()
if tt.err {
require.Error(t, err)
require.Nil(t, got)
return
}
require.NoError(t, err)
require.Equal(t, tt.want, got)
})
}
}

func TestResourceUnmarshalJSON(t *testing.T) {
tests := []struct {
name string
data []byte
want rpc.Resource
err bool
}{
{
name: "l1 gas",
data: []byte("l1_gas"),
want: rpc.ResourceL1Gas,
},
{
name: "l2 gas",
data: []byte("l2_gas"),
want: rpc.ResourceL2Gas,
},
{
name: "l1 data gas",
data: []byte("l1_data_gas"),
want: rpc.ResourceL1DataGas,
},
{
name: "error",
data: []byte("unknown"),
err: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var got rpc.Resource
err := got.UnmarshalJSON(tt.data)
if tt.err {
require.Error(t, err)
require.Zero(t, got)
return
}
require.NoError(t, err)
require.Equal(t, tt.want, got)
})
}
}

0 comments on commit 8617b5c

Please sign in to comment.