github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/rpc/author/author_test.go (about)

     1  // Go Substrate RPC Client (GSRPC) provides APIs and types around Polkadot and any Substrate-based author RPC calls
     2  //
     3  // Copyright 2020 Stafi Protocol
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package author
    18  
    19  import (
    20  	"os"
    21  	"testing"
    22  
    23  	"github.com/stafiprotocol/go-substrate-rpc-client/pkg/client"
    24  	"github.com/stafiprotocol/go-substrate-rpc-client/pkg/rpcmocksrv"
    25  )
    26  
    27  var author *Author
    28  
    29  func TestMain(m *testing.M) {
    30  	s := rpcmocksrv.New()
    31  	err := s.RegisterName("author", &mockSrv)
    32  	if err != nil {
    33  		panic(err)
    34  	}
    35  
    36  	cl, err := client.Connect(s.URL)
    37  	// cl, err := client.Connect(config.Default().RPCURL)
    38  	if err != nil {
    39  		panic(err)
    40  	}
    41  	author = NewAuthor(cl)
    42  
    43  	os.Exit(m.Run())
    44  }
    45  
    46  // MockSrv holds data and methods exposed by the RPC Mock Server used in integration tests
    47  type MockSrv struct {
    48  	submitExtrinsicHash string
    49  	pendingExtrinsics   []string
    50  }
    51  
    52  func (s *MockSrv) SubmitExtrinsic(extrinsic string) string {
    53  	return mockSrv.submitExtrinsicHash
    54  }
    55  
    56  func (s *MockSrv) PendingExtrinsics() []string {
    57  	return mockSrv.pendingExtrinsics
    58  }
    59  
    60  // mockSrv sets default data used in tests. This data might become stale when substrate is updated – just run the tests
    61  // against real servers and update the values stored here. To do that, replace s.URL with
    62  // config.Default().RPCURL
    63  var mockSrv = MockSrv{
    64  	submitExtrinsicHash: "0x9a8ef9794ded03b4d1ae45034351210e87f970f1f9500994bca82f9cd5a1166e",
    65  	pendingExtrinsics:   []string{"0x290284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d00a023bbe883405b5fac2aa114093fcf3d0802d2f3d3715e09129b00a4bf741048caf53d8c7d97e872caa703e7d04f174a4e2ed4acadee4173a8b6bab7e45c0a06000c000600ff8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48e56c"}, //nolint:lll
    66  }