2017-10-23 15:56:29 +00:00
|
|
|
package fakes
|
|
|
|
|
2017-11-28 16:45:21 +00:00
|
|
|
import (
|
2017-12-04 18:54:33 +00:00
|
|
|
"math/big"
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
2018-01-06 20:31:53 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
2017-11-28 16:45:21 +00:00
|
|
|
)
|
2017-10-23 15:56:29 +00:00
|
|
|
|
2018-07-18 20:59:40 +00:00
|
|
|
type MockBlockChain struct {
|
2018-07-20 16:37:46 +00:00
|
|
|
fetchContractDataErr error
|
|
|
|
fetchContractDataPassedAbi string
|
|
|
|
fetchContractDataPassedAddress string
|
|
|
|
fetchContractDataPassedMethod string
|
Moved fetcher to generic directory (methods have to remain public since it is in seperate package now), added FetchHash method, created ERC20 and generic getters which call the fetcher with specific contract methods (GetTotalSupply, GetBalance, GetAllowance for ERC20 getter, and GetOwner, GetStoppedStatus, GetStringName, GetHashName, GetStringSymbol, GetHashSymbol, and GetDecimals for generic getter). Getter tests cover all but GetBalance and GetAllowance, and also cover all of the Fetcher methods- but with only nil methodArgs. GetAllowance and GetBalance tests are not working against infura and these are the only contract method calls with arguments passed in so I suspect this might be where the issue lies. Have tested GetBalance using previous version of FetchContractData without the variadic input to the Pack method and it fails with the same error so I don’t think it is due to those changes.
2018-08-15 04:17:22 +00:00
|
|
|
fetchContractDataPassedMethodArgs []interface{}
|
2018-07-20 16:37:46 +00:00
|
|
|
fetchContractDataPassedResult interface{}
|
|
|
|
fetchContractDataPassedBlockNumber int64
|
|
|
|
getBlockByNumberErr error
|
|
|
|
lastBlock *big.Int
|
|
|
|
node core.Node
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMockBlockChain() *MockBlockChain {
|
|
|
|
return &MockBlockChain{
|
|
|
|
node: core.Node{GenesisBlock: "GENESIS", NetworkID: 1, ID: "x123", ClientName: "Geth"},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (blockChain *MockBlockChain) SetFetchContractDataErr(err error) {
|
|
|
|
blockChain.fetchContractDataErr = err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (blockChain *MockBlockChain) SetLastBlock(blockNumber *big.Int) {
|
|
|
|
blockChain.lastBlock = blockNumber
|
|
|
|
}
|
|
|
|
|
|
|
|
func (blockChain *MockBlockChain) SetGetBlockByNumberErr(err error) {
|
|
|
|
blockChain.getBlockByNumberErr = err
|
2018-07-17 21:23:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 20:59:40 +00:00
|
|
|
func (blockChain *MockBlockChain) GetHeaderByNumber(blockNumber int64) (core.Header, error) {
|
2018-07-20 16:37:46 +00:00
|
|
|
return core.Header{BlockNumber: blockNumber}, nil
|
2018-02-13 16:31:57 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 16:58:06 +00:00
|
|
|
func (blockChain *MockBlockChain) FetchContractData(abiJSON string, address string, method string, methodArgs []interface{}, result interface{}, blockNumber int64) error {
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChain.fetchContractDataPassedAbi = abiJSON
|
|
|
|
blockChain.fetchContractDataPassedAddress = address
|
|
|
|
blockChain.fetchContractDataPassedMethod = method
|
2018-08-09 16:58:06 +00:00
|
|
|
blockChain.fetchContractDataPassedMethodArgs = methodArgs
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChain.fetchContractDataPassedResult = result
|
|
|
|
blockChain.fetchContractDataPassedBlockNumber = blockNumber
|
|
|
|
return blockChain.fetchContractDataErr
|
2018-03-12 19:09:20 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 20:59:40 +00:00
|
|
|
func (blockChain *MockBlockChain) CallContract(contractHash string, input []byte, blockNumber *big.Int) ([]byte, error) {
|
2018-07-20 16:37:46 +00:00
|
|
|
return []byte{}, nil
|
2017-12-07 19:32:16 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 20:59:40 +00:00
|
|
|
func (blockChain *MockBlockChain) LastBlock() *big.Int {
|
2018-07-20 16:37:46 +00:00
|
|
|
return blockChain.lastBlock
|
2017-12-20 20:06:22 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 20:59:40 +00:00
|
|
|
func (blockChain *MockBlockChain) GetLogs(contract core.Contract, startingBlock *big.Int, endingBlock *big.Int) ([]core.Log, error) {
|
2018-07-20 16:37:46 +00:00
|
|
|
return []core.Log{}, nil
|
2017-12-11 21:08:00 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 20:59:40 +00:00
|
|
|
func (blockChain *MockBlockChain) Node() core.Node {
|
2018-07-17 21:23:07 +00:00
|
|
|
return blockChain.node
|
2017-11-27 15:39:53 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 20:59:40 +00:00
|
|
|
func (blockChain *MockBlockChain) GetBlockByNumber(blockNumber int64) (core.Block, error) {
|
2018-07-20 16:37:46 +00:00
|
|
|
return core.Block{Number: blockNumber}, blockChain.getBlockByNumberErr
|
2017-11-06 20:36:12 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
// TODO: handle methodArg being nil (can't match nil to nil in Gomega)
|
2018-08-09 16:58:06 +00:00
|
|
|
func (blockChain *MockBlockChain) AssertFetchContractDataCalledWith(abiJSON string, address string, method string, methodArgs []interface{}, result interface{}, blockNumber int64) {
|
2018-07-20 16:37:46 +00:00
|
|
|
Expect(blockChain.fetchContractDataPassedAbi).To(Equal(abiJSON))
|
|
|
|
Expect(blockChain.fetchContractDataPassedAddress).To(Equal(address))
|
|
|
|
Expect(blockChain.fetchContractDataPassedMethod).To(Equal(method))
|
|
|
|
Expect(blockChain.fetchContractDataPassedResult).To(Equal(result))
|
|
|
|
Expect(blockChain.fetchContractDataPassedBlockNumber).To(Equal(blockNumber))
|
2017-10-23 15:56:29 +00:00
|
|
|
}
|