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 Dec 3, 2021
1 parent 8533e90 commit 4fe6304
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
3 changes: 3 additions & 0 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,9 @@ func (eth *ExchangeWallet) Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Co
for _, redemption := range form.Redemptions {
var secretHash [32]byte
copy(secretHash[:], redemption.Spends.SecretHash)
if secretHash != sha256.Sum256(redemption.Secret) {
return fail(fmt.Errorf("Redeem: secretHash %x != sha256(%x)", secretHash, redemption.Secret))
}
swapData, err := eth.node.swap(eth.ctx, secretHash, form.AssetVersion)
if err != nil {
return nil, nil, 0, fmt.Errorf("Redeem: error finding swap state: %w", err)
Expand Down
50 changes: 20 additions & 30 deletions client/asset/eth/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,7 @@ func (n *testNode) initiate(ctx context.Context, contracts []*asset.Contract, ma
if n.initErr != nil {
return nil, n.initErr
}
// baseTx := &types.DynamicFeeTx{
// Nonce: n.nonce,
// GasFeeCap: maxFeeRate,
// GasTipCap: MinGasTipCap,
// Gas: dexeth.InitGas(len(contracts)),
// Value: opts.Value,
// Data: []byte{},
// }
tx = types.NewTx(&types.DynamicFeeTx{})
// n.nonce++
// n.lastInitiation = initTx{
// initiations: initiations,
// hash: tx.Hash(),
// opts: opts,
// }
n.nonce++
return types.NewTx(&types.DynamicFeeTx{
Nonce: n.nonce,
Expand All @@ -140,22 +126,7 @@ func (n *testNode) redeem(ctx context.Context, redemptions []*asset.Redemption,
if n.redeemErr != nil {
return nil, n.redeemErr
}
/*baseTx := &types.DynamicFeeTx{
Nonce: n.nonce,
GasFeeCap: opts.GasFeeCap,
GasTipCap: opts.GasTipCap,
Gas: opts.GasLimit,
Value: opts.Value,
Data: []byte{},
}*/
//tx := types.NewTx(baseTx)
n.nonce++
// n.lastRedemption = redeemTx{
// redemptions: redemptions,
// hash: tx.Hash(),
// opts: opts,
// tx: tx,
// }
return types.NewTx(&types.DynamicFeeTx{
Nonce: n.nonce,
}), nil
Expand Down Expand Up @@ -1273,11 +1244,30 @@ func TestRedeem(t *testing.T) {
AssetVersion: 0,
},
},
{
name: "hash of secret != secretHash",
expectError: true,
form: asset.RedeemForm{
Redemptions: []*asset.Redemption{
{
Spends: &asset.AuditInfo{
SecretHash: secretHashes[1][:],
Coin: &coin{
id: encode.RandomBytes(32),
},
},
Secret: secrets[0][:],
},
},
FeeSuggestion: 100,
AssetVersion: 0,
},
},
{
name: "empty redemptions slice error",
expectError: true,
form: asset.RedeemForm{
Redemptions: []*asset.Redemption{},
Redemptions: []*asset.Redemption{},
FeeSuggestion: 100,
AssetVersion: 0,
},
Expand Down

0 comments on commit 4fe6304

Please sign in to comment.