diff --git a/app/app_test.go b/app/app_test.go index b4399fb..269b295 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -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, diff --git a/types/tx.go b/types/tx.go index 74dc88e..d667763 100644 --- a/types/tx.go +++ b/types/tx.go @@ -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 { diff --git a/types/tx_test.go b/types/tx_test.go index aa55cd4..c513f31 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -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()