github.com/gagliardetto/solana-go@v1.11.0/programs/serum/rpc_test.go (about) 1 // Copyright 2021 github.com/gagliardetto 2 // This file has been modified by github.com/gagliardetto 3 // 4 // Copyright 2020 dfuse Platform Inc. 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // 10 // http://www.apache.org/licenses/LICENSE-2.0 11 // 12 // Unless required by applicable law or agreed to in writing, software 13 // distributed under the License is distributed on an "AS IS" BASIS, 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 // See the License for the specific language governing permissions and 16 // limitations under the License. 17 18 package serum 19 20 import ( 21 "context" 22 "fmt" 23 "os" 24 "testing" 25 26 "github.com/gagliardetto/solana-go/rpc/ws" 27 28 "github.com/gagliardetto/solana-go/rpc" 29 30 "github.com/stretchr/testify/require" 31 32 "github.com/gagliardetto/solana-go" 33 ) 34 35 func TestFetchMarket(t *testing.T) { 36 rpcURL := os.Getenv("RPC_URL") 37 if rpcURL == "" { 38 t.Skip("Setup 'RPC_URL' to run test i.e. 'https://api.mainnet-beta.solana.com'") 39 return 40 } 41 42 // 43 44 client := rpc.New(rpcURL) 45 ctx := context.Background() 46 47 openOrderAdd, err := solana.PublicKeyFromBase58("jFoHUkNDC767PyK11cZM4zyNcpjLqFnSjaqEYp5GVBr") 48 require.NoError(t, err) 49 50 openOrders, err := FetchOpenOrders(ctx, client, openOrderAdd) 51 require.NoError(t, err) 52 53 cnt, err := json.MarshalIndent(openOrders.OpenOrders, "", " ") 54 55 require.NoError(t, err) 56 57 fmt.Println(string(cnt)) 58 } 59 60 func TestStreamOpenOrders(t *testing.T) { 61 rpcURL := os.Getenv("RPC_URL") 62 if rpcURL == "" { 63 t.Skip("Setup 'RPC_URL' to run test i.e. 'wss://api.mainnet-beta.solana.com'") 64 return 65 } 66 client, err := ws.Connect(context.Background(), rpcURL) 67 require.NoError(t, err) 68 69 err = StreamOpenOrders(client) 70 require.NoError(t, err) 71 }