Skip to content

Commit

Permalink
fix a couple go tests
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Jan 10, 2024
1 parent 87f505a commit 7746ac2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 0 additions & 2 deletions relayer/pkg/chainlink/txm/nonce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func TestNonceManager_NextSequence(t *testing.T) {

// should fail with invalid address
randAddr1 := starknetutils.BigIntToFelt(big.NewInt(1))
require.NoError(t, err)
_, err = nm.NextSequence(randAddr1, chainId)
require.Error(t, err)
assert.Contains(t, err.Error(), fmt.Sprintf("nonce tracking does not exist for key: %s", randAddr1.String()))
Expand Down Expand Up @@ -93,7 +92,6 @@ func TestNonceManager_IncrementNextSequence(t *testing.T) {

// should fail with invalid address
randAddr1 := starknetutils.BigIntToFelt(big.NewInt(1))
require.NoError(t, err)
err = nm.IncrementNextSequence(randAddr1, chainId, initPlusOne)
require.Error(t, err)
assert.Contains(t, err.Error(), fmt.Sprintf("nonce tracking does not exist for key: %s", randAddr1.String()))
Expand Down
3 changes: 2 additions & 1 deletion relayer/pkg/chainlink/txm/txstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func NewTxStore(current *felt.Felt) *TxStore {
}
}

// TODO: Save should make a copy otherwise wee're modiffying the same memory and could loop
func (s *TxStore) Save(nonce *felt.Felt, hash string) error {
s.lock.Lock()
defer s.lock.Unlock()
Expand All @@ -45,7 +46,7 @@ func (s *TxStore) Save(nonce *felt.Felt, hash string) error {
// find next unused nonce
_, exists := s.nonceToHash[s.currentNonce]
for exists {
s.currentNonce.Add(s.currentNonce, new(felt.Felt).SetUint64(1))
s.currentNonce = new(felt.Felt).Add(s.currentNonce, new(felt.Felt).SetUint64(1))
_, exists = s.nonceToHash[s.currentNonce]
}
return nil
Expand Down
10 changes: 5 additions & 5 deletions relayer/pkg/chainlink/txm/txstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestTxStore(t *testing.T) {

s := NewTxStore(&felt.Zero)
assert.Equal(t, 0, s.InflightCount())
require.NoError(t, s.Save(&felt.Zero, "0x0"))
require.NoError(t, s.Save(new(felt.Felt).SetUint64(0), "0x0"))
assert.Equal(t, 1, s.InflightCount())
assert.Equal(t, []string{"0x0"}, s.GetUnconfirmed())
require.NoError(t, s.Confirm("0x0"))
Expand All @@ -31,10 +31,10 @@ func TestTxStore(t *testing.T) {
t.Parallel()

// create
s := NewTxStore(&felt.Zero)
s := NewTxStore(new(felt.Felt).SetUint64(0))

// accepts tx in order
require.NoError(t, s.Save(&felt.Zero, "0x0"))
require.NoError(t, s.Save(new(felt.Felt).SetUint64(0), "0x0"))
assert.Equal(t, 1, s.InflightCount())
assert.Equal(t, new(felt.Felt).SetUint64(1), s.currentNonce)

Expand All @@ -54,7 +54,7 @@ func TestTxStore(t *testing.T) {
assert.Equal(t, new(felt.Felt).SetUint64(3), s.currentNonce)

// rejects old nonce
require.ErrorContains(t, s.Save(&felt.Zero, "0xold"), "nonce too low: 0 < 3 (lowest)")
require.ErrorContains(t, s.Save(new(felt.Felt).SetUint64(0), "0xold"), "nonce too low: 0 < 3 (lowest)")
assert.Equal(t, 4, s.InflightCount())

// reject already in use nonce
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestTxStore(t *testing.T) {
t.Parallel()

// init store
s := NewTxStore(&felt.Zero)
s := NewTxStore(new(felt.Felt).SetUint64(0))
for i := 0; i < 5; i++ {
require.NoError(t, s.Save(new(felt.Felt).SetUint64(uint64(i)), "0x"+fmt.Sprintf("%d", i)))
}
Expand Down

0 comments on commit 7746ac2

Please sign in to comment.