This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
create2transfer_test.go
75 lines (63 loc) · 1.86 KB
/
create2transfer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package storage
import (
"math/big"
"testing"
"github.com/Worldcoin/hubble-commander/models"
"github.com/Worldcoin/hubble-commander/models/enums/txtype"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
var (
create2Transfer = models.Create2Transfer{
TransactionBase: models.TransactionBase{
Hash: common.BigToHash(big.NewInt(1234)),
TxType: txtype.Create2Transfer,
FromStateID: 1,
Amount: models.MakeUint256(1000),
Fee: models.MakeUint256(100),
Nonce: models.MakeUint256(0),
Signature: models.MakeRandomSignature(),
CommitmentSlot: &models.CommitmentSlot{
BatchID: models.MakeUint256(1),
IndexInBatch: 0,
IndexInCommitment: 0,
},
},
ToPublicKey: account2.PublicKey,
}
)
type Create2TransferTestSuite struct {
*require.Assertions
suite.Suite
storage *TestStorage
}
func (s *Create2TransferTestSuite) SetupSuite() {
s.Assertions = require.New(s.T())
}
func (s *Create2TransferTestSuite) SetupTest() {
var err error
s.storage, err = NewTestStorage()
s.NoError(err)
err = s.storage.AccountTree.SetSingle(&account2)
s.NoError(err)
}
func (s *Create2TransferTestSuite) TearDownTest() {
err := s.storage.Teardown()
s.NoError(err)
}
func (s *Create2TransferTestSuite) TestGetCreate2Transfer_DifferentTxType() {
err := s.storage.AddTransaction(&transfer)
s.NoError(err)
_, err = s.storage.GetCreate2Transfer(transfer.Hash)
s.ErrorIs(err, NewNotFoundError("transaction"))
}
func (s *Create2TransferTestSuite) TestGetCreate2Transfer_NonexistentTransaction() {
hash := common.BytesToHash([]byte{1, 2, 3, 4, 5})
res, err := s.storage.GetCreate2Transfer(hash)
s.ErrorIs(err, NewNotFoundError("transaction"))
s.Nil(res)
}
func TestCreate2TransferTestSuite(t *testing.T) {
suite.Run(t, new(Create2TransferTestSuite))
}