Skip to content

Commit

Permalink
chore: extract mock node info from tests to remove duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Dec 13, 2023
1 parent 841eb53 commit c50795e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c50795e

Please sign in to comment.