Skip to content

Commit

Permalink
Merge pull request #54 from FourthState/aditya/double-spend-fix
Browse files Browse the repository at this point in the history
Fix double spend bug
  • Loading branch information
colin-axner authored Jul 7, 2018
2 parents f726fd5 + 3a3a6be commit dc516ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestBadSpendMsg(t *testing.T) {

// Construct a SpendMsg
var msg = types.SpendMsg{
Blknum1: 0,
Blknum1: 1,
Txindex1: 0,
Oindex1: 0,
DepositNum1: 0,
Expand Down
3 changes: 3 additions & 0 deletions types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (msg SpendMsg) ValidateBasic() sdk.Error {
if !utils.ValidAddress(msg.Newowner1) {
return ErrInvalidAddress(DefaultCodespace, "No recipients of transaction")
}
if msg.Blknum1 == msg.Blknum2 && msg.Txindex1 == msg.Txindex2 && msg.Oindex1 == msg.Oindex2 && msg.DepositNum1 == msg.DepositNum2 {
return ErrInvalidTransaction(DefaultCodespace, "Cannot spend same position twice")
}

switch {

Expand Down
10 changes: 10 additions & 0 deletions types/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ func TestInvalidSpendDeposit(t *testing.T) {
assert.Equal(t, sdk.CodeType(106), err.Code(), err.Error())
}

// Creates an invalid transaction spending same position twice
func TestInvalidPosition(t *testing.T) {
var msg1 = GenSpendMsgWithAddresses()
// Set second position equal to first position
msg1.Txindex2 = 0

err := msg1.ValidateBasic()
assert.Equal(t, sdk.CodeType(106), err.Code(), err.Error())
}

// Tests GetSigners method
func TestGetSigners(t *testing.T) {
msg := GenBasicSpendMsg()
Expand Down

0 comments on commit dc516ff

Please sign in to comment.