This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Cat storage diff transformer
Update schema after rebase migrations Fix small issues from review
- Loading branch information
Showing
7 changed files
with
521 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
pkg/transformers/storage_diffs/maker/cat/cat_suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cat_test | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
"io/ioutil" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestCat(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Cat Suite") | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
logrus.SetOutput(ioutil.Discard) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
pkg/transformers/storage_diffs/maker/cat/mappings_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
package cat_test | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/vulcanize/vulcanizedb/pkg/fakes" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/cat" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/test_helpers" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared" | ||
"math/big" | ||
) | ||
|
||
var _ = Describe("Cat storage mappings", func() { | ||
const ( | ||
fakeIlk = "fakeIlk" | ||
fakeFlip = "2" | ||
) | ||
|
||
var ( | ||
storageRepository *test_helpers.MockMakerStorageRepository | ||
mappings cat.CatMappings | ||
) | ||
|
||
BeforeEach(func() { | ||
storageRepository = &test_helpers.MockMakerStorageRepository{} | ||
mappings = cat.CatMappings{StorageRepository: storageRepository} | ||
}) | ||
|
||
Describe("looking up static keys", func() { | ||
It("returns value metadata if key exists", func() { | ||
Expect(mappings.Lookup(cat.NFlipKey)).To(Equal(cat.NFlipMetadata)) | ||
Expect(mappings.Lookup(cat.LiveKey)).To(Equal(cat.LiveMetadata)) | ||
Expect(mappings.Lookup(cat.VatKey)).To(Equal(cat.VatMetadata)) | ||
Expect(mappings.Lookup(cat.PitKey)).To(Equal(cat.PitMetadata)) | ||
Expect(mappings.Lookup(cat.VowKey)).To(Equal(cat.VowMetadata)) | ||
}) | ||
|
||
It("returns error if key does not exist", func() { | ||
_, err := mappings.Lookup(common.HexToHash(fakes.FakeHash.Hex())) | ||
|
||
Expect(err).To(HaveOccurred()) | ||
Expect(err).To(MatchError(shared.ErrStorageKeyNotFound{Key: fakes.FakeHash.Hex()})) | ||
}) | ||
}) | ||
|
||
Describe("looking up dynamic keys", func() { | ||
It("refreshes mappings from repository if key not found", func() { | ||
_, _ = mappings.Lookup(fakes.FakeHash) | ||
|
||
Expect(storageRepository.GetIlksCalled).To(BeTrue()) | ||
Expect(storageRepository.GetMaxFlipCalled).To(BeTrue()) | ||
}) | ||
|
||
It("returns error if ilks lookup fails", func() { | ||
storageRepository.GetIlksError = fakes.FakeError | ||
|
||
_, err := mappings.Lookup(fakes.FakeHash) | ||
|
||
Expect(err).To(HaveOccurred()) | ||
Expect(err).To(MatchError(fakes.FakeError)) | ||
}) | ||
|
||
It("returns error if max flip lookup fails", func() { | ||
storageRepository.GetMaxFlipError = fakes.FakeError | ||
|
||
_, err := mappings.Lookup(fakes.FakeHash) | ||
|
||
Expect(err).To(HaveOccurred()) | ||
Expect(err).To(MatchError(fakes.FakeError)) | ||
}) | ||
|
||
It("interpolates flips up to max", func() { | ||
storageRepository.MaxFlip = big.NewInt(1) | ||
|
||
_, err := mappings.Lookup(storage_diffs.GetMapping(storage_diffs.IndexTwo, "0")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
_, err = mappings.Lookup(storage_diffs.GetMapping(storage_diffs.IndexTwo, "1")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
Describe("ilk", func() { | ||
var ilkFlipKey = common.BytesToHash(crypto.Keccak256(common.FromHex(fakeIlk + cat.IlksMappingIndex))) | ||
|
||
BeforeEach(func() { | ||
storageRepository.Ilks = []string{fakeIlk} | ||
}) | ||
|
||
It("returns value metadata for ilk flip", func() { | ||
expectedMetadata := shared.StorageValueMetadata{ | ||
Name: cat.IlkFlip, | ||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk}, | ||
Type: shared.Address, | ||
} | ||
Expect(mappings.Lookup(ilkFlipKey)).To(Equal(expectedMetadata)) | ||
}) | ||
|
||
It("returns value metadata for ilk chop", func() { | ||
ilkChopKey := storage_diffs.GetIncrementedKey(ilkFlipKey, 1) | ||
expectedMetadata := shared.StorageValueMetadata{ | ||
Name: cat.IlkChop, | ||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk}, | ||
Type: shared.Uint256, | ||
} | ||
Expect(mappings.Lookup(ilkChopKey)).To(Equal(expectedMetadata)) | ||
}) | ||
|
||
It("returns value metadata for ilk lump", func() { | ||
ilkLumpKey := storage_diffs.GetIncrementedKey(ilkFlipKey, 2) | ||
expectedMetadata := shared.StorageValueMetadata{ | ||
Name: cat.IlkLump, | ||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk}, | ||
Type: shared.Uint256, | ||
} | ||
Expect(mappings.Lookup(ilkLumpKey)).To(Equal(expectedMetadata)) | ||
}) | ||
}) | ||
|
||
Describe("flip", func() { | ||
var flipIlkKey = common.BytesToHash(crypto.Keccak256(common.FromHex(fakeFlip + cat.FlipsMappingIndex))) | ||
|
||
BeforeEach(func() { | ||
storageRepository.MaxFlip = big.NewInt(2) | ||
}) | ||
|
||
It("returns value metadata for flip ilk", func() { | ||
expectedMetadata := shared.StorageValueMetadata{ | ||
Name: cat.FlipIlk, | ||
Keys: map[shared.Key]string{shared.Flip: fakeFlip}, | ||
Type: shared.Bytes32, | ||
} | ||
actualMetadata, err := mappings.Lookup(flipIlkKey) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(actualMetadata).To(Equal(expectedMetadata)) | ||
}) | ||
|
||
It("returns value metadata for flip urn", func() { | ||
flipUrnKey := storage_diffs.GetIncrementedKey(flipIlkKey, 1) | ||
expectedMetadata := shared.StorageValueMetadata{ | ||
Name: cat.FlipUrn, | ||
Keys: map[shared.Key]string{shared.Flip: fakeFlip}, | ||
Type: shared.Bytes32, | ||
} | ||
actualMetadata, err := mappings.Lookup(flipUrnKey) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(actualMetadata).To(Equal(expectedMetadata)) | ||
}) | ||
|
||
It("returns value metadata for flip ink", func() { | ||
flipInkKey := storage_diffs.GetIncrementedKey(flipIlkKey, 2) | ||
expectedMetadata := shared.StorageValueMetadata{ | ||
Name: cat.FlipInk, | ||
Keys: map[shared.Key]string{shared.Flip: fakeFlip}, | ||
Type: shared.Uint256, | ||
} | ||
actualMetadata, err := mappings.Lookup(flipInkKey) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(actualMetadata).To(Equal(expectedMetadata)) | ||
}) | ||
|
||
It("returns value metadata for flip tab", func() { | ||
flipTabKey := storage_diffs.GetIncrementedKey(flipIlkKey, 3) | ||
expectedMetadata := shared.StorageValueMetadata{ | ||
Name: cat.FlipTab, | ||
Keys: map[shared.Key]string{shared.Flip: fakeFlip}, | ||
Type: shared.Uint256, | ||
} | ||
actualMetadata, err := mappings.Lookup(flipTabKey) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(actualMetadata).To(Equal(expectedMetadata)) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.