forked from gagliardetto/solana-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction_error_test.go
60 lines (53 loc) · 1.37 KB
/
transaction_error_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package solana
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseTransactionError(t *testing.T) {
t.Parallel()
var (
err error
ok bool
)
err, ok = ParseTransactionError(nil, "AccountInUse")
require.True(t, ok)
require.ErrorIs(t, err, TransactionError_AccountInUse{})
err, ok = ParseTransactionError(nil, map[string]interface{}{
"InstructionError": []interface{}{
float64(1),
"InvalidArgument",
},
})
require.True(t, ok)
var e *TransactionError
require.ErrorAs(t, err, &e)
assert.Equal(t, &TransactionError_InstructionError{
Index: 1,
Cause: InstructionError_InvalidArgument{},
}, err.(interface{ Unwrap() error }).Unwrap())
err, ok = ParseTransactionError(nil, map[string]interface{}{
"InstructionError": []interface{}{
float64(1),
map[string]interface{}{
"Custom": float64(16),
},
},
})
assert.Equal(t, &TransactionError_InstructionError{
Index: 1,
Cause: &InstructionError_Custom{
Code: 16,
Cause: nil,
},
}, err.(interface{ Unwrap() error }).Unwrap())
err, ok = ParseTransactionError(nil, map[string]interface{}{
"InsufficientFundsForRent": map[string]interface{}{
"account_index": float64(1),
},
})
assert.Equal(t, &TransactionError_InsufficientFundsForRent{
AccountIndex: 1,
Account: nil,
}, err.(interface{ Unwrap() error }).Unwrap())
}