fix(Collectibles): Add database tests

Fix #3355
This commit is contained in:
Michal Iskierko 2023-03-28 13:06:35 +02:00 committed by Michał Iskierko
parent 9267ad46c5
commit 8304f8bf88
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
package collectibles
import (
"io/ioutil"
"testing"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/protocol/sqlite"
)
func TestDatabaseSuite(t *testing.T) {
suite.Run(t, new(DatabaseSuite))
}
type DatabaseSuite struct {
suite.Suite
db *Database
}
func (s *DatabaseSuite) SetupTest() {
s.db = nil
dbPath, err := ioutil.TempFile("", "status-go-collectibles-db-")
s.NoError(err, "creating temp file for db")
db, err := appdatabase.InitializeDB(dbPath.Name(), "", sqlite.ReducedKDFIterationsNumber)
s.NoError(err, "creating sqlite db instance")
err = sqlite.Migrate(db)
s.NoError(err, "protocol migrate")
s.db = &Database{db: db}
}
func (s *DatabaseSuite) TestAddOwner() {
owners, err := s.db.GetTokenOwners(5, "0x123")
s.Require().NoError(err)
s.Require().Len(owners, 0)
err = s.db.AddTokenOwners(5, "0x123", []string{"A", "B"})
s.Require().NoError(err)
owners, err = s.db.GetTokenOwners(5, "0x123")
s.Require().NoError(err)
s.Require().Len(owners, 2)
s.Equal(owners[0].Amount, 1)
s.Equal(owners[1].Amount, 1)
err = s.db.AddTokenOwners(5, "0x123", []string{"a"})
s.Require().NoError(err)
owners, err = s.db.GetTokenOwners(5, "0x123")
s.Require().NoError(err)
s.Require().Len(owners, 2)
amount, err := s.db.GetAmount(5, "0x123", "A")
s.Require().NoError(err)
s.Equal(amount, 2)
amount, err = s.db.GetAmount(5, "0x123", "B")
s.Require().NoError(err)
s.Equal(amount, 1)
}