From c50795e934eeb730fe2a1c6813821ee48f4288cf Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 13 Dec 2023 12:59:49 +0700 Subject: [PATCH] chore: extract mock node info from tests to remove duplication --- service_test.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/service_test.go b/service_test.go index be6ae159..877e40b5 100644 --- a/service_test.go +++ b/service_test.go @@ -74,6 +74,14 @@ const nip47PayJsonNoInvoice = ` const mockInvoice = "lnbc10n1pjdy9aepp5ftvu6fucndg5mp5ww4ghsduqrxgr4rtcwelrln4jzxhem5qw022qhp50kncf9zk35xg4lxewt4974ry6mudygsztsz8qn3ar8pn3mtpe50scqzzsxqyz5vqsp5zyzp3dyn98g7sjlgy4nvujq3rh9xxsagytcyx050mf3rtrx3sn4s9qyyssq7af24ljqf5uzgnz4ualxhvffryh3kpkvvj76ah9yrgdvu494lmfrdf36h5wuhshzemkvrtg2zu70uk0fd9fcmxgl3j9748dvvx9ey9gqpr4jjd" const mockPaymentHash = "4ad9cd27989b514d868e755178378019903a8d78767e3fceb211af9dd00e7a94" // for the above invoice +var mockNodeInfo = NodeInfo{ + Alias: "bob", + Color: "#3399FF", + Pubkey: "123pubkey", + Network: "testnet", + BlockHeight: 12, + BlockHash: "123blockhash", +} // TODO: split up into individual tests func TestHandleEvent(t *testing.T) { @@ -442,12 +450,12 @@ func TestHandleEvent(t *testing.T) { } err = json.Unmarshal([]byte(decrypted), received) assert.NoError(t, err) - assert.Equal(t, "bob", received.Result.(*Nip47GetInfoResponse).Alias) - assert.Equal(t, "#3399FF", received.Result.(*Nip47GetInfoResponse).Color) - assert.Equal(t, "123pubkey", received.Result.(*Nip47GetInfoResponse).Pubkey) - assert.Equal(t, "testnet", received.Result.(*Nip47GetInfoResponse).Network) - assert.Equal(t, uint32(12), received.Result.(*Nip47GetInfoResponse).BlockHeight) - assert.Equal(t, "123blockhash", received.Result.(*Nip47GetInfoResponse).BlockHash) + assert.Equal(t, mockNodeInfo.Alias, received.Result.(*Nip47GetInfoResponse).Alias) + assert.Equal(t, mockNodeInfo.Color, received.Result.(*Nip47GetInfoResponse).Color) + assert.Equal(t, mockNodeInfo.Pubkey, received.Result.(*Nip47GetInfoResponse).Pubkey) + assert.Equal(t, mockNodeInfo.Network, received.Result.(*Nip47GetInfoResponse).Network) + assert.Equal(t, mockNodeInfo.BlockHeight, received.Result.(*Nip47GetInfoResponse).BlockHeight) + assert.Equal(t, mockNodeInfo.BlockHash, received.Result.(*Nip47GetInfoResponse).BlockHash) assert.Equal(t, []string{"get_info"}, received.Result.(*Nip47GetInfoResponse).Methods) } @@ -491,14 +499,7 @@ func (mln *MockLn) GetBalance(ctx context.Context, senderPubkey string) (balance } func (mln *MockLn) GetInfo(ctx context.Context, senderPubkey string) (info *NodeInfo, err error) { - return &NodeInfo{ - Alias: "bob", - Color: "#3399FF", - Pubkey: "123pubkey", - Network: "testnet", - BlockHeight: 12, - BlockHash: "123blockhash", - }, nil + return &mockNodeInfo, nil } func (mln *MockLn) MakeInvoice(ctx context.Context, senderPubkey string, amount int64, description string, descriptionHash string, expiry int64) (invoice string, paymentHash string, err error) {