2020-11-09 05:53:09 -08:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
2020-11-09 09:39:51 -08:00
|
|
|
"fmt"
|
2020-11-09 05:53:09 -08:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWSClient_ProgramSubscribe(t *testing.T) {
|
|
|
|
|
2020-11-09 09:39:51 -08:00
|
|
|
done := make(chan bool)
|
|
|
|
c, err := NewWSClient("ws://api.mainnet-beta.solana.com:80/rpc")
|
2020-11-09 05:53:09 -08:00
|
|
|
require.NoError(t, err)
|
2020-11-09 09:39:51 -08:00
|
|
|
|
|
|
|
var closed bool
|
|
|
|
err = c.ProgramSubscribe("EUqojwWA2rd19FZrzeBncJsm38Jm1hEhE3zsmX3bRc2o", "", func(programResult result) {
|
|
|
|
if closed {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r := programResult.(*ProgramResult)
|
|
|
|
fmt.Println("result", r)
|
|
|
|
closed = true
|
|
|
|
close(done)
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
case <-time.After(2000 * time.Millisecond):
|
|
|
|
t.Error("failed to run the giving time")
|
|
|
|
}
|
2020-11-09 05:53:09 -08:00
|
|
|
}
|