diff --git a/utils/websocket.go b/utils/websocket.go index c4e265e..e2a73bf 100644 --- a/utils/websocket.go +++ b/utils/websocket.go @@ -4,6 +4,7 @@ import ( "encoding/json" "log" "net/url" + "os" "strconv" "strings" @@ -17,6 +18,7 @@ import ( var aminoCdc = amino.NewCodec() func init() { + log.SetOutput(os.Stdout) ctypes.RegisterAmino(aminoCdc) } @@ -77,7 +79,7 @@ func (app SantaApp) ListenNewBLock(isTest bool) { if blockEvent.Block.Height%triggerInterval == 0 { txHash, err := app.SendTx(blockEvent.Block.ChainID) if err != nil { - log.Fatal("[Fail] to send tx", err) + log.Printf("[Fail] to send tx: %s", err.Error()) } log.Printf("[Success] Height: %d,\tTxHash: %s\n", blockEvent.Block.Height, txHash) diff --git a/utils/websocket_test.go b/utils/websocket_test.go index a41bfc0..c22c61a 100644 --- a/utils/websocket_test.go +++ b/utils/websocket_test.go @@ -1,15 +1,17 @@ package utils import ( - "os" "bytes" "log" + "os" "strings" "time" "testing" + "github.com/stretchr/testify/require" ) + func TestWebsocketListen(t *testing.T) { app := setupWithPlentyBalanceAccount(t) @@ -18,11 +20,11 @@ func TestWebsocketListen(t *testing.T) { var logBuf bytes.Buffer log.SetOutput(&logBuf) - defer log.SetOutput(os.Stderr) + defer log.SetOutput(os.Stdout) app.TriggerInterval = "1" app.ListenNewBLock(true) - + result := logBuf.String() require.True(t, strings.Contains(result, "[Success]")) -} \ No newline at end of file +}