github.com/datachainlab/burrow@v0.25.0/execution/errors/errors_test.go (about) 1 package errors 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestErrorCode_MarshalJSON(t *testing.T) { 13 ec := NewException(ErrorCodeDataStackOverflow, "arrgh") 14 bs, err := json.Marshal(ec) 15 require.NoError(t, err) 16 17 ecOut := new(Exception) 18 err = json.Unmarshal(bs, ecOut) 19 require.NoError(t, err) 20 21 assert.Equal(t, ec, ecOut) 22 } 23 24 func TestCode_String(t *testing.T) { 25 err := ErrorCodeCodeOutOfBounds 26 fmt.Println(err.Error()) 27 } 28 29 func TestFirstOnly(t *testing.T) { 30 err := FirstOnly() 31 // This will be a wrapped nil - it should not register as first error 32 var ex CodedError = (*Exception)(nil) 33 err.PushError(ex) 34 // This one should 35 realErr := ErrorCodef(ErrorCodeInsufficientBalance, "real error") 36 err.PushError(realErr) 37 assert.True(t, realErr.Equal(err.Error())) 38 }