Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil committed Jan 24, 2025
1 parent f7494e1 commit c99a65c
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
51 changes: 51 additions & 0 deletions rpc/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1365,3 +1365,54 @@ func TestTransactionStatus(t *testing.T) {
})
}
}

func TestResourceMarshalText(t *testing.T) {
tests := []struct {
resource rpc.Resource
text string
hasError bool
}{
{rpc.ResourceL1Gas, "l1_gas", false},
{rpc.ResourceL2Gas, "l2_gas", false},
{rpc.ResourceL1DataGas, "l1_data_gas", false},
{rpc.Resource(999), "error", true},
}

for _, test := range tests {
t.Run(test.text, func(t *testing.T) {
b, err := test.resource.MarshalText()
if test.hasError {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, test.text, string(b))
})
}
}

func TestResourceUnmarshalText(t *testing.T) {
tests := []struct {
resource rpc.Resource
text string
hasError bool
}{
{rpc.ResourceL1Gas, `"l1_gas"`, false},
{rpc.ResourceL2Gas, `"l2_gas"`, false},
{rpc.ResourceL1DataGas, `"l1_data_gas"`, false},
{rpc.Resource(999), "error", true},
}

for _, test := range tests {
t.Run(test.text, func(t *testing.T) {
var r rpc.Resource
err := r.UnmarshalText([]byte(test.text))
if test.hasError {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, test.resource, r)
})
}
}
51 changes: 51 additions & 0 deletions starknet/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,54 @@ func TestUnmarshalFinalityStatus(t *testing.T) {

require.ErrorContains(t, json.Unmarshal([]byte(`"ABC"`), fs), "unknown FinalityStatus")
}

func TestResourceMarshalText(t *testing.T) {
tests := []struct {
resource starknet.Resource
text string
hasError bool
}{
{starknet.ResourceL1Gas, "L1_GAS", false},
{starknet.ResourceL2Gas, "L2_GAS", false},
{starknet.ResourceL1DataGas, "L1_DATA_GAS", false},
{starknet.Resource(999), "error", true},
}

for _, test := range tests {
t.Run(test.text, func(t *testing.T) {
b, err := test.resource.MarshalText()
if test.hasError {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, test.text, string(b))
})
}
}

func TestResourceUnmarshalText(t *testing.T) {
tests := []struct {
resource starknet.Resource
text string
hasError bool
}{
{starknet.ResourceL1Gas, "L1_GAS", false},
{starknet.ResourceL2Gas, "L2_GAS", false},
{starknet.ResourceL1DataGas, "L1_DATA_GAS", false},
{starknet.Resource(999), "error", true},
}

for _, test := range tests {
t.Run(test.text, func(t *testing.T) {
var r starknet.Resource
err := r.UnmarshalText([]byte(test.text))
if test.hasError {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, test.resource, r)
})
}
}

0 comments on commit c99a65c

Please sign in to comment.