forked from cerc-io/ipld-eth-server
adjust block/uncle reward tests and add methods to pkg/geth blockchain and ethclient for direct fetching of eth balances
This commit is contained in:
@@ -45,6 +45,10 @@ type MockBlockChain struct {
|
||||
lastBlock *big.Int
|
||||
node core.Node
|
||||
Transactions []core.TransactionModel
|
||||
passedAccountAddress common.Address
|
||||
passedBlockNumer *big.Int
|
||||
passedAccountBalance *big.Int
|
||||
getAccountBalanceErr error
|
||||
}
|
||||
|
||||
func NewMockBlockChain() *MockBlockChain {
|
||||
@@ -141,3 +145,17 @@ func (chain *MockBlockChain) AssertFetchContractDataCalledWith(abiJSON string, a
|
||||
func (blockChain *MockBlockChain) AssertGetEthLogsWithCustomQueryCalledWith(query ethereum.FilterQuery) {
|
||||
Expect(blockChain.logQuery).To(Equal(query))
|
||||
}
|
||||
|
||||
func (blockChain *MockBlockChain) SetGetAccountBalanceErr(err error) {
|
||||
blockChain.getAccountBalanceErr = err
|
||||
}
|
||||
|
||||
func (blockChain *MockBlockChain) SetGetAccountBalance(balance *big.Int) {
|
||||
blockChain.passedAccountBalance = balance
|
||||
}
|
||||
|
||||
func (blockChain *MockBlockChain) GetAccountBalance(address common.Address, blockNumber *big.Int) (*big.Int, error) {
|
||||
blockChain.passedAccountAddress = address
|
||||
blockChain.passedBlockNumer = blockNumber
|
||||
return blockChain.passedAccountBalance, blockChain.getAccountBalanceErr
|
||||
}
|
||||
|
||||
@@ -54,6 +54,11 @@ type MockEthClient struct {
|
||||
passedMethod string
|
||||
transactionSenderErr error
|
||||
transactionReceiptErr error
|
||||
passedAddress common.Address
|
||||
passedBlockNumber *big.Int
|
||||
passedBalance *big.Int
|
||||
balanceAtErr error
|
||||
passedbalanceAtContext context.Context
|
||||
}
|
||||
|
||||
func NewMockEthClient() *MockEthClient {
|
||||
@@ -208,3 +213,24 @@ func (client *MockEthClient) AssertFilterLogsCalledWith(ctx context.Context, q e
|
||||
func (client *MockEthClient) AssertBatchCalledWith(method string) {
|
||||
Expect(client.passedMethod).To(Equal(method))
|
||||
}
|
||||
|
||||
func (client *MockEthClient) SetBalanceAtErr(err error) {
|
||||
client.balanceAtErr = err
|
||||
}
|
||||
|
||||
func (client *MockEthClient) SetBalanceAt(balance *big.Int) {
|
||||
client.passedBalance = balance
|
||||
}
|
||||
|
||||
func (client *MockEthClient) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) {
|
||||
client.passedbalanceAtContext = ctx
|
||||
client.passedAddress = account
|
||||
client.passedBlockNumber = blockNumber
|
||||
return client.passedBalance, client.balanceAtErr
|
||||
}
|
||||
|
||||
func (client *MockEthClient) AssertBalanceAtCalled(ctx context.Context, account common.Address, blockNumber *big.Int) {
|
||||
Expect(client.passedbalanceAtContext).To(Equal(ctx))
|
||||
Expect(client.passedAddress).To(Equal(account))
|
||||
Expect(client.passedBlockNumber).To(Equal(blockNumber))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user