Skip to content

Commit

Permalink
test: integration tests for premium
Browse files Browse the repository at this point in the history
This commit is to modify and add integration tests
for the addition of premium.
  • Loading branch information
YusukeShimizu committed Dec 23, 2023
1 parent 1ec38e5 commit 8870169
Show file tree
Hide file tree
Showing 10 changed files with 1,564 additions and 984 deletions.
15 changes: 9 additions & 6 deletions peerswaprpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (p *PeerswapServer) SwapOut(ctx context.Context, request *SwapOutRequest) (
return nil, fmt.Errorf("peer is not connected")
}

swapOut, err := p.swaps.SwapOut(peerId, request.Asset, shortId.String(), pk, request.SwapAmount)
swapOut, err := p.swaps.SwapOut(peerId, request.Asset, shortId.String(), pk, request.SwapAmount, request.GetPremiumLimit())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (p *PeerswapServer) SwapIn(ctx context.Context, request *SwapInRequest) (*S
return nil, fmt.Errorf("peer is not connected")
}

swapIn, err := p.swaps.SwapIn(peerId, request.Asset, shortId.String(), pk, request.SwapAmount)
swapIn, err := p.swaps.SwapIn(peerId, request.Asset, shortId.String(), pk, request.SwapAmount, request.GetPremiumLimit())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -376,10 +376,12 @@ func (p *PeerswapServer) ListPeers(ctx context.Context, request *ListPeersReques
}

peerSwapPeers = append(peerSwapPeers, &PeerSwapPeer{
NodeId: v.PubKey,
SwapsAllowed: poll.PeerAllowed,
SupportedAssets: poll.Assets,
Channels: getPeerSwapChannels(v.PubKey, channelRes.Channels),
NodeId: v.PubKey,
SwapsAllowed: poll.PeerAllowed,
SwapInPremiumRatePpm: poll.SwapInPremiumRatePPM,
SwapOutPremiumRatePpm: poll.SwapOutPremiumRatePPM,
SupportedAssets: poll.Assets,
Channels: getPeerSwapChannels(v.PubKey, channelRes.Channels),
AsSender: &SwapStats{
SwapsOut: SenderSwapsOut,
SwapsIn: SenderSwapsIn,
Expand Down Expand Up @@ -571,6 +573,7 @@ func PrettyprintFromServiceSwap(swap *swap.SwapStateMachine) *PrettyPrintSwap {
ClaimTxId: swap.Data.ClaimTxId,
CancelMessage: swap.Data.GetCancelMessage(),
LndChanId: lnd_chan_id,
PremiumAmount: swap.Data.GetPremium(),
}
}

Expand Down
42 changes: 24 additions & 18 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ func Test_Reload(t *testing.T) {
policy, err := create(strings.NewReader(conf))
assert.NoError(t, err)
assert.EqualValues(t, &Policy{
ReserveOnchainMsat: defaultReserveOnchainMsat,
PeerAllowlist: []string{peer1, peer2},
SuspiciousPeerList: defaultSuspiciousPeerList,
AcceptAllPeers: accept,
MinSwapAmountMsat: defaultMinSwapAmountMsat,
AllowNewSwaps: defaultAllowNewSwaps,
ReserveOnchainMsat: defaultReserveOnchainMsat,
PeerAllowlist: []string{peer1, peer2},
SuspiciousPeerList: defaultSuspiciousPeerList,
AcceptAllPeers: accept,
MinSwapAmountMsat: defaultMinSwapAmountMsat,
AllowNewSwaps: defaultAllowNewSwaps,
SwapInPremiumRatePPM: defaultSwapInPremiumRatePPM,
SwapOutPremiumRatePPM: defaultSwapOutPremiumRatePPM,
}, policy)

newPeer := "new_peer"
Expand All @@ -98,12 +100,14 @@ func Test_Reload(t *testing.T) {
err = policy.reload(strings.NewReader(newConf))
assert.NoError(t, err)
assert.EqualValues(t, &Policy{
ReserveOnchainMsat: defaultReserveOnchainMsat,
PeerAllowlist: []string{newPeer},
SuspiciousPeerList: []string{newPeer},
AcceptAllPeers: defaultAcceptAllPeers,
MinSwapAmountMsat: defaultMinSwapAmountMsat,
AllowNewSwaps: defaultAllowNewSwaps,
ReserveOnchainMsat: defaultReserveOnchainMsat,
PeerAllowlist: []string{newPeer},
SuspiciousPeerList: []string{newPeer},
AcceptAllPeers: defaultAcceptAllPeers,
MinSwapAmountMsat: defaultMinSwapAmountMsat,
AllowNewSwaps: defaultAllowNewSwaps,
SwapInPremiumRatePPM: defaultSwapInPremiumRatePPM,
SwapOutPremiumRatePPM: defaultSwapOutPremiumRatePPM,
}, policy)
}

Expand All @@ -121,12 +125,14 @@ func Test_Reload_NoOverrideOnError(t *testing.T) {
policy, err := create(strings.NewReader(conf))
assert.NoError(t, err)
assert.EqualValues(t, &Policy{
ReserveOnchainMsat: defaultReserveOnchainMsat,
PeerAllowlist: []string{peer1, peer2},
SuspiciousPeerList: defaultSuspiciousPeerList,
AcceptAllPeers: accept,
MinSwapAmountMsat: defaultMinSwapAmountMsat,
AllowNewSwaps: defaultAllowNewSwaps,
ReserveOnchainMsat: defaultReserveOnchainMsat,
PeerAllowlist: []string{peer1, peer2},
SuspiciousPeerList: defaultSuspiciousPeerList,
AcceptAllPeers: accept,
MinSwapAmountMsat: defaultMinSwapAmountMsat,
AllowNewSwaps: defaultAllowNewSwaps,
SwapInPremiumRatePPM: defaultSwapInPremiumRatePPM,
SwapOutPremiumRatePPM: defaultSwapOutPremiumRatePPM,
}, policy)

// copy policy
Expand Down
2 changes: 1 addition & 1 deletion swap/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func TestMessageFromUnexpectedPeer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
aliceSwap, err := aliceSwapService.SwapOut(peer, "btc", channelId, initiator, amount, 0)
aliceSwap, err := aliceSwapService.SwapOut(peer, "btc", channelId, initiator, amount, 1000)
if err != nil {
t.Fatalf(" error swapping oput %v: ", err)
}
Expand Down
Loading

0 comments on commit 8870169

Please sign in to comment.