mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-12 14:57:12 +00:00
int/nonce fixes
This commit is contained in:
parent
37a8a6cd65
commit
19bd3bb2e2
@ -94,7 +94,7 @@ func init() {
|
|||||||
func makeDefaultSendTx(t *testing.T, typ string, addr []byte, amt uint64) *types.SendTx {
|
func makeDefaultSendTx(t *testing.T, typ string, addr []byte, amt uint64) *types.SendTx {
|
||||||
nonce := getNonce(t, typ, user[0].Address)
|
nonce := getNonce(t, typ, user[0].Address)
|
||||||
tx := types.NewSendTx()
|
tx := types.NewSendTx()
|
||||||
tx.AddInputWithNonce(user[0].PubKey, amt, nonce)
|
tx.AddInputWithNonce(user[0].PubKey, amt, nonce+1)
|
||||||
tx.AddOutput(addr, amt)
|
tx.AddOutput(addr, amt)
|
||||||
return tx
|
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 {
|
func makeDefaultNameTx(t *testing.T, typ string, name, value string, amt, fee uint64) *types.NameTx {
|
||||||
nonce := getNonce(t, typ, user[0].Address)
|
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])
|
tx.Sign(user[0])
|
||||||
return tx
|
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)
|
// rpc call wrappers (fail on err)
|
||||||
|
|
||||||
// get an account's nonce
|
// 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]
|
client := clients[typ]
|
||||||
ac, err := client.GetAccount(addr)
|
ac, err := client.GetAccount(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -132,7 +132,7 @@ func getNonce(t *testing.T, typ string, addr []byte) uint64 {
|
|||||||
if ac.Account == nil {
|
if ac.Account == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return uint64(ac.Account.Sequence)
|
return ac.Account.Sequence
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the account
|
// get the account
|
||||||
|
@ -237,7 +237,7 @@ func testNameReg(t *testing.T, typ string) {
|
|||||||
// try to update as non owner, should fail
|
// try to update as non owner, should fail
|
||||||
nonce := getNonce(t, typ, user[1].Address)
|
nonce := getNonce(t, typ, user[1].Address)
|
||||||
data2 := "this is not my beautiful house"
|
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])
|
tx.Sign(user[1])
|
||||||
_, err := client.BroadcastTx(tx)
|
_, err := client.BroadcastTx(tx)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -25,23 +25,15 @@ func (tx *SendTx) AddInput(st AccountGetter, pubkey account.PubKey, amt uint64)
|
|||||||
if acc == nil {
|
if acc == nil {
|
||||||
return fmt.Errorf("Invalid address %X from pubkey %X", addr, pubkey)
|
return fmt.Errorf("Invalid address %X from pubkey %X", addr, pubkey)
|
||||||
}
|
}
|
||||||
|
return tx.AddInputWithNonce(pubkey, amt, acc.Sequence+1)
|
||||||
tx.Inputs = append(tx.Inputs, &TxInput{
|
|
||||||
Address: addr,
|
|
||||||
Amount: amt,
|
|
||||||
Sequence: uint(acc.Sequence) + 1,
|
|
||||||
Signature: account.SignatureEd25519{},
|
|
||||||
PubKey: pubkey,
|
|
||||||
})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
addr := pubkey.Address()
|
||||||
tx.Inputs = append(tx.Inputs, &TxInput{
|
tx.Inputs = append(tx.Inputs, &TxInput{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Amount: amt,
|
Amount: amt,
|
||||||
Sequence: uint(nonce) + 1,
|
Sequence: nonce,
|
||||||
Signature: account.SignatureEd25519{},
|
Signature: account.SignatureEd25519{},
|
||||||
PubKey: pubkey,
|
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)
|
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
|
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()
|
addr := from.Address()
|
||||||
input := &TxInput{
|
input := &TxInput{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Amount: amt,
|
Amount: amt,
|
||||||
Sequence: uint(nonce) + 1,
|
Sequence: nonce,
|
||||||
Signature: account.SignatureEd25519{},
|
Signature: account.SignatureEd25519{},
|
||||||
PubKey: from,
|
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)
|
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
|
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()
|
addr := from.Address()
|
||||||
input := &TxInput{
|
input := &TxInput{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Amount: amt,
|
Amount: amt,
|
||||||
Sequence: uint(nonce) + 1,
|
Sequence: nonce,
|
||||||
Signature: account.SignatureEd25519{},
|
Signature: account.SignatureEd25519{},
|
||||||
PubKey: from,
|
PubKey: from,
|
||||||
}
|
}
|
||||||
@ -161,23 +153,15 @@ func (tx *BondTx) AddInput(st AccountGetter, pubkey account.PubKey, amt uint64)
|
|||||||
if acc == nil {
|
if acc == nil {
|
||||||
return fmt.Errorf("Invalid address %X from pubkey %X", addr, pubkey)
|
return fmt.Errorf("Invalid address %X from pubkey %X", addr, pubkey)
|
||||||
}
|
}
|
||||||
|
return tx.AddInputWithNonce(pubkey, amt, acc.Sequence+1)
|
||||||
tx.Inputs = append(tx.Inputs, &TxInput{
|
|
||||||
Address: addr,
|
|
||||||
Amount: amt,
|
|
||||||
Sequence: uint(acc.Sequence) + 1,
|
|
||||||
Signature: account.SignatureEd25519{},
|
|
||||||
PubKey: pubkey,
|
|
||||||
})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
addr := pubkey.Address()
|
||||||
tx.Inputs = append(tx.Inputs, &TxInput{
|
tx.Inputs = append(tx.Inputs, &TxInput{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Amount: amt,
|
Amount: amt,
|
||||||
Sequence: uint(nonce) + 1,
|
Sequence: nonce,
|
||||||
Signature: account.SignatureEd25519{},
|
Signature: account.SignatureEd25519{},
|
||||||
PubKey: pubkey,
|
PubKey: pubkey,
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user