Skip to content

Commit

Permalink
Updates based on review.
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed Nov 29, 2021
1 parent 49632d5 commit b525e86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 5 additions & 7 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,22 +727,22 @@ func (r *swapReceipt) Expiration() time.Time {
func (r *swapReceipt) Coin() asset.Coin {
return &coin{
value: r.value,
id: dex.Bytes(r.txHash[:]),
id: r.txHash[:],
}
}

// Contract returns the swap's secret hash.
func (r *swapReceipt) Contract() dex.Bytes {
return dex.Bytes(r.secretHash[:])
return r.secretHash[:]
}

// String returns a string representation of the swapReceipt.
func (r *swapReceipt) String() string {
return fmt.Sprintf("tx hash: %x, secret hash: %x", r.txHash, r.secretHash)
return fmt.Sprintf("{ tx hash: %x, secret hash: %x }", r.txHash, r.secretHash)
}

// SignedRefund returns an empty byte array. ETH does not support a pre-signed
// redeem script becuase the nonce needed in the transaction cannot be previously
// redeem script because the nonce needed in the transaction cannot be previously
// determined.
func (*swapReceipt) SignedRefund() dex.Bytes {
return dex.Bytes{}
Expand Down Expand Up @@ -861,10 +861,8 @@ func (eth *ExchangeWallet) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin
eth.unlockFunds(swaps.Inputs)
var change asset.Coin
changeAmount := totalInputValue - totalUsedValue
if changeAmount > 0 {
if changeAmount > 0 && swaps.LockChange {
change = eth.createAmountCoin(changeAmount)
}
if swaps.LockChange && change != nil {
eth.lockFunds(asset.Coins{change})
}

Expand Down
11 changes: 5 additions & 6 deletions client/asset/eth/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,10 +1080,6 @@ func TestSwap(t *testing.T) {
t.Fatalf("%v: receipt coin value: %v != expected: %v",
testName, receipt.Coin().Value(), contract.Value)
}
if len(receipt.Contract()) != srveth.SecretHashSize {
t.Fatalf("%v: expected length of contract to be %v but got %v",
testName, srveth.SecretHashSize, len(receipt.Contract()))
}
if !bytes.Equal(receipt.Contract(), contract.SecretHash[:]) {
t.Fatalf("%v, contract: %x != secret hash in input: %x",
testName, receipt.Contract(), contract.SecretHash)
Expand Down Expand Up @@ -1170,8 +1166,11 @@ func TestSwap(t *testing.T) {
gasNeededForSwaps(len(swaps.Contracts))*swaps.FeeRate
if expectedChangeValue == 0 && changeCoin != nil {
t.Fatalf("%v: change coin should be nil if change is 0", testName)
} else if expectedChangeValue > 0 && changeCoin == nil {
t.Fatalf("%v: change coin should not be nil if there is expected change", testName)
} else if expectedChangeValue > 0 && changeCoin == nil && swaps.LockChange {
t.Fatalf("%v: change coin should not be nil if there is expected change and change is locked",
testName)
} else if !swaps.LockChange && changeCoin != nil {
t.Fatalf("%v: change should be nil if LockChange==False", testName)
} else if changeCoin != nil && changeCoin.Value() != expectedChangeValue {
t.Fatalf("%v: expected change value %v != change coin value: %v",
testName, expectedChangeValue, changeCoin.Value())
Expand Down

0 comments on commit b525e86

Please sign in to comment.