2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2018 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-05-05 20:25:54 +00:00
|
|
|
|
|
|
|
package every_block_test
|
|
|
|
|
|
|
|
import (
|
2018-08-31 19:48:43 +00:00
|
|
|
"math/big"
|
|
|
|
"strconv"
|
|
|
|
|
2018-05-05 20:25:54 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-08-31 19:48:43 +00:00
|
|
|
|
2018-05-05 20:25:54 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/examples/erc20_watcher/every_block"
|
2018-08-27 02:55:09 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/examples/generic"
|
2018-05-05 20:25:54 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/examples/test_helpers"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
2018-07-20 16:37:46 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
2018-11-07 21:50:43 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/omni/constants"
|
2018-05-05 20:25:54 +00:00
|
|
|
)
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
func setLastBlockOnChain(blockChain *fakes.MockBlockChain, blockNumber int64) {
|
2018-05-05 20:25:54 +00:00
|
|
|
blockNumberString := strconv.FormatInt(blockNumber, 10)
|
|
|
|
lastBlockOnChain := big.Int{}
|
|
|
|
lastBlockOnChain.SetString(blockNumberString, 10)
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChain.SetLastBlock(&lastBlockOnChain)
|
2018-05-05 20:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ = Describe("Everyblock transformers", func() {
|
|
|
|
var db *postgres.DB
|
2018-07-20 16:37:46 +00:00
|
|
|
var blockChain *fakes.MockBlockChain
|
2018-05-05 20:25:54 +00:00
|
|
|
var blockNumber int64
|
|
|
|
var blockId int64
|
|
|
|
var err error
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChain = fakes.NewMockBlockChain()
|
2018-08-27 02:55:09 +00:00
|
|
|
blockNumber = generic.DaiConfig.FirstBlock
|
2018-05-05 20:25:54 +00:00
|
|
|
lastBlockNumber := blockNumber + 1
|
|
|
|
db = test_helpers.CreateNewDatabase()
|
2018-07-20 16:37:46 +00:00
|
|
|
setLastBlockOnChain(blockChain, lastBlockNumber)
|
2018-05-05 20:25:54 +00:00
|
|
|
|
|
|
|
blockRepository := repositories.NewBlockRepository(db)
|
|
|
|
|
|
|
|
blockId, err = blockRepository.CreateOrUpdateBlock(core.Block{Number: blockNumber})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
_, err = blockRepository.CreateOrUpdateBlock(core.Block{Number: lastBlockNumber})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
|
|
|
It("creates a token_supply record for each block in the given range", func() {
|
2018-09-19 17:22:05 +00:00
|
|
|
transformer, err := every_block.NewERC20TokenTransformer(db, blockChain, generic.DaiConfig)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2018-05-05 20:25:54 +00:00
|
|
|
transformer.Execute()
|
|
|
|
|
|
|
|
var tokenSupplyCount int
|
2018-09-19 17:22:05 +00:00
|
|
|
err = db.QueryRow(`SELECT COUNT(*) FROM token_supply where block_id = $1`, blockId).Scan(&tokenSupplyCount)
|
2018-05-05 20:25:54 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(tokenSupplyCount).To(Equal(1))
|
|
|
|
|
|
|
|
var tokenSupply test_helpers.TokenSupplyDBRow
|
|
|
|
err = db.Get(&tokenSupply, `SELECT * from token_supply where block_id = $1`, blockId)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(tokenSupply.BlockID).To(Equal(blockId))
|
|
|
|
Expect(tokenSupply.TokenAddress).To(Equal(constants.DaiContractAddress))
|
|
|
|
Expect(tokenSupply.Supply).To(Equal(int64(0)))
|
|
|
|
})
|
|
|
|
})
|