Browse Source

int/nonce fixes

pull/83/head
Ethan Buchman 9 years ago
parent
commit
19bd3bb2e2
3 changed files with 17 additions and 33 deletions
  1. +4
    -4
      rpc/test/helpers.go
  2. +1
    -1
      rpc/test/tests.go
  3. +12
    -28
      types/tx_utils.go

+ 4
- 4
rpc/test/helpers.go View File

@ -94,7 +94,7 @@ func init() {
func makeDefaultSendTx(t *testing.T, typ string, addr []byte, amt uint64) *types.SendTx {
nonce := getNonce(t, typ, user[0].Address)
tx := types.NewSendTx()
tx.AddInputWithNonce(user[0].PubKey, amt, nonce)
tx.AddInputWithNonce(user[0].PubKey, amt, nonce+1)
tx.AddOutput(addr, amt)
return tx
}
@ -114,7 +114,7 @@ func makeDefaultCallTx(t *testing.T, typ string, addr, code []byte, amt, gasLim,
func makeDefaultNameTx(t *testing.T, typ string, name, value string, amt, fee uint64) *types.NameTx {
nonce := getNonce(t, typ, user[0].Address)
tx := types.NewNameTxWithNonce(user[0].PubKey, name, value, amt, fee, nonce)
tx := types.NewNameTxWithNonce(user[0].PubKey, name, value, amt, fee, nonce+1)
tx.Sign(user[0])
return tx
}
@ -123,7 +123,7 @@ func makeDefaultNameTx(t *testing.T, typ string, name, value string, amt, fee ui
// rpc call wrappers (fail on err)
// get an account's nonce
func getNonce(t *testing.T, typ string, addr []byte) uint64 {
func getNonce(t *testing.T, typ string, addr []byte) uint {
client := clients[typ]
ac, err := client.GetAccount(addr)
if err != nil {
@ -132,7 +132,7 @@ func getNonce(t *testing.T, typ string, addr []byte) uint64 {
if ac.Account == nil {
return 0
}
return uint64(ac.Account.Sequence)
return ac.Account.Sequence
}
// get the account


+ 1
- 1
rpc/test/tests.go View File

@ -237,7 +237,7 @@ func testNameReg(t *testing.T, typ string) {
// try to update as non owner, should fail
nonce := getNonce(t, typ, user[1].Address)
data2 := "this is not my beautiful house"
tx = types.NewNameTxWithNonce(user[1].PubKey, name, data2, amt, fee, nonce)
tx = types.NewNameTxWithNonce(user[1].PubKey, name, data2, amt, fee, nonce+1)
tx.Sign(user[1])
_, err := client.BroadcastTx(tx)
if err == nil {


+ 12
- 28
types/tx_utils.go View File

@ -25,23 +25,15 @@ func (tx *SendTx) AddInput(st AccountGetter, pubkey account.PubKey, amt uint64)
if acc == nil {
return fmt.Errorf("Invalid address %X from pubkey %X", addr, pubkey)
}
tx.Inputs = append(tx.Inputs, &TxInput{
Address: addr,
Amount: amt,
Sequence: uint(acc.Sequence) + 1,
Signature: account.SignatureEd25519{},
PubKey: pubkey,
})
return nil
return tx.AddInputWithNonce(pubkey, amt, acc.Sequence+1)
}
func (tx *SendTx) AddInputWithNonce(pubkey account.PubKey, amt, nonce uint64) error {
func (tx *SendTx) AddInputWithNonce(pubkey account.PubKey, amt uint64, nonce uint) error {
addr := pubkey.Address()
tx.Inputs = append(tx.Inputs, &TxInput{
Address: addr,
Amount: amt,
Sequence: uint(nonce) + 1,
Sequence: nonce,
Signature: account.SignatureEd25519{},
PubKey: pubkey,
})
@ -75,16 +67,16 @@ func NewCallTx(st AccountGetter, from account.PubKey, to, data []byte, amt, gasL
return nil, fmt.Errorf("Invalid address %X from pubkey %X", addr, from)
}
nonce := uint64(acc.Sequence)
nonce := acc.Sequence + 1
return NewCallTxWithNonce(from, to, data, amt, gasLimit, fee, nonce), nil
}
func NewCallTxWithNonce(from account.PubKey, to, data []byte, amt, gasLimit, fee, nonce uint64) *CallTx {
func NewCallTxWithNonce(from account.PubKey, to, data []byte, amt, gasLimit, fee uint64, nonce uint) *CallTx {
addr := from.Address()
input := &TxInput{
Address: addr,
Amount: amt,
Sequence: uint(nonce) + 1,
Sequence: nonce,
Signature: account.SignatureEd25519{},
PubKey: from,
}
@ -113,16 +105,16 @@ func NewNameTx(st AccountGetter, from account.PubKey, name, data string, amt, fe
return nil, fmt.Errorf("Invalid address %X from pubkey %X", addr, from)
}
nonce := uint64(acc.Sequence)
nonce := acc.Sequence + 1
return NewNameTxWithNonce(from, name, data, amt, fee, nonce), nil
}
func NewNameTxWithNonce(from account.PubKey, name, data string, amt, fee, nonce uint64) *NameTx {
func NewNameTxWithNonce(from account.PubKey, name, data string, amt, fee uint64, nonce uint) *NameTx {
addr := from.Address()
input := &TxInput{
Address: addr,
Amount: amt,
Sequence: uint(nonce) + 1,
Sequence: nonce,
Signature: account.SignatureEd25519{},
PubKey: from,
}
@ -161,23 +153,15 @@ func (tx *BondTx) AddInput(st AccountGetter, pubkey account.PubKey, amt uint64)
if acc == nil {
return fmt.Errorf("Invalid address %X from pubkey %X", addr, pubkey)
}
tx.Inputs = append(tx.Inputs, &TxInput{
Address: addr,
Amount: amt,
Sequence: uint(acc.Sequence) + 1,
Signature: account.SignatureEd25519{},
PubKey: pubkey,
})
return nil
return tx.AddInputWithNonce(pubkey, amt, acc.Sequence+1)
}
func (tx *BondTx) AddInputWithNonce(pubkey account.PubKey, amt, nonce uint64) error {
func (tx *BondTx) AddInputWithNonce(pubkey account.PubKey, amt uint64, nonce uint) error {
addr := pubkey.Address()
tx.Inputs = append(tx.Inputs, &TxInput{
Address: addr,
Amount: amt,
Sequence: uint(nonce) + 1,
Sequence: nonce,
Signature: account.SignatureEd25519{},
PubKey: pubkey,
})


Loading…
Cancel
Save