Skip to content

Commit f8e4dc6

Browse files
authored
swap: fix TestHandshake and TestEmitCheque (ethersphere#1721)
1 parent 506ab97 commit f8e4dc6

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

swap/protocol_test.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,15 @@ func TestHandshake(t *testing.T) {
7171
err = protocolTester.TestExchanges(p2ptest.Exchange{
7272
Label: "TestHandshake",
7373
Triggers: []p2ptest.Trigger{
74-
{
75-
Code: 1,
76-
Msg: &EmitChequeMsg{
77-
Cheque: cheque,
78-
},
79-
Peer: debitor.ID(),
80-
},
81-
},
82-
Expects: []p2ptest.Expect{
8374
{
8475
Code: 0,
8576
Msg: &HandshakeMsg{
8677
ContractAddress: swap.owner.Contract,
8778
},
8879
Peer: creditor.ID(),
8980
},
81+
},
82+
Expects: []p2ptest.Expect{
9083
{
9184
Code: 0,
9285
Msg: &HandshakeMsg{
@@ -182,16 +175,11 @@ func TestEmitCheque(t *testing.T) {
182175
if creditorSwap.balances[debitor.ID()] != 0 {
183176
t.Fatalf("Expected debitor balance to have been reset to %d, but it is %d", 0, creditorSwap.balances[debitor.ID()])
184177
}
185-
/*
186-
TODO: This test actually fails now, because the two Swaps create independent backends,
187-
thus when handling the cheque, it will actually complain (check ERROR log output)
188-
with `error="no contract code at given address"`.
189-
Therefore, the `lastReceivedCheque` is not being saved, and this check would fail.
190-
So TODO is to find out how to address this (should be by having same backend when creating the Swap)
191-
if creditorSwap.loadLastReceivedCheque(debitor.ID()) != cheque {
192-
t.Fatalf("Expected exactly one cheque at creditor, but there are %d:", len(creditorSwap.cheques))
193-
}
194-
*/
178+
recvCheque := creditorSwap.loadLastReceivedCheque(debitor)
179+
log.Debug("expected cheque", "cheque", recvCheque)
180+
if recvCheque != cheque {
181+
t.Fatalf("Expected exactly one cheque at creditor, but there are %d:", len(creditorSwap.cheques))
182+
}
195183
}
196184

197185
// TestTriggerPaymentThreshold is to test that the whole cheque protocol is triggered

0 commit comments

Comments
 (0)