changes to repo and repo tests so that supply table is organized and accessed by token_address

This commit is contained in:
Ian Norden 2018-08-12 15:35:23 -05:00
parent bea712ba10
commit 99e549b3df
3 changed files with 20 additions and 14 deletions

View File

@ -84,11 +84,13 @@ func (tsp *ERC20TokenRepository) MissingSupplyBlocks(startingBlock, highestBlock
&blockNumbers,
`SELECT number FROM BLOCKS
LEFT JOIN token_supply ON blocks.id = block_id
AND token_address = $1
WHERE block_id ISNULL
AND eth_node_id = $1
AND number >= $2
AND number <= $3
AND eth_node_id = $2
AND number >= $3
AND number <= $4
LIMIT 20`,
tokenAddress,
tsp.NodeID,
startingBlock,
highestBlock,

View File

@ -27,7 +27,7 @@ import (
"math/rand"
)
var _ = Describe("ERC20 Token Repository", func() {
var _ = Describe("ERC20 Token Supply Repository", func() {
var db *postgres.DB
var blockId int64
var blockNumber int64
@ -136,7 +136,7 @@ var _ = Describe("ERC20 Token Repository", func() {
Describe("MissingBlocks", func() {
It("returns the block numbers for which an associated TokenSupply record hasn't been created", func() {
createTokenSupplyFor(repository, blockNumber)
createTokenSupplyFor(repository, blockNumber, testAddress)
newBlockNumber := blockNumber + 1
test_helpers.CreateBlock(newBlockNumber, blockRepository)
@ -156,7 +156,7 @@ var _ = Describe("ERC20 Token Repository", func() {
})
It("does not return numbers that already have an associated TokenSupply record", func() {
createTokenSupplyFor(repository, blockNumber)
createTokenSupplyFor(repository, blockNumber, testAddress)
blocks, err := repository.MissingSupplyBlocks(blockNumber, blockNumber, testAddress)
Expect(blocks).To(BeEmpty())
@ -165,7 +165,7 @@ var _ = Describe("ERC20 Token Repository", func() {
})
It("deletes the token supply record when the associated block is deleted", func() {
err := repository.CreateSupply(every_block.TokenSupply{BlockNumber: blockNumber, Value: "0"})
err := repository.CreateSupply(every_block.TokenSupply{BlockNumber: blockNumber, TokenAddress: testAddress, Value: "0"})
Expect(err).NotTo(HaveOccurred())
var count int
@ -182,16 +182,20 @@ var _ = Describe("ERC20 Token Repository", func() {
})
})
func supplyModel(blockNumber int64, tokenAddress string, supplyValue string) every_block.TokenSupply {
func supplyModel(blockNumber int64, tokenAddress, supplyValue string) every_block.TokenSupply {
return every_block.TokenSupply{
Value: supplyValue,
TokenAddress: tokenAddress,
BlockNumber: int64(blockNumber),
BlockNumber: blockNumber,
}
}
func createTokenSupplyFor(repository every_block.ERC20TokenRepository, blockNumber int64) {
err := repository.CreateSupply(every_block.TokenSupply{BlockNumber: blockNumber, Value: "0"})
func createTokenSupplyFor(repository every_block.ERC20TokenRepository, blockNumber int64, tokenAddress string) {
err := repository.CreateSupply(every_block.TokenSupply{
BlockNumber: blockNumber,
TokenAddress: tokenAddress,
Value: "0",
})
Expect(err).NotTo(HaveOccurred())
}

View File

@ -24,8 +24,8 @@ import (
)
type TokenSupplyDBRow struct {
ID int64
Supply int64
ID int64 `db:"id"`
Supply int64 `db:"supply"`
BlockID int64 `db:"block_id"`
TokenAddress string `db:"token_address"`
}