Skip to content

Commit

Permalink
fix governance getReward unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yoomee1313 committed May 16, 2024
1 parent fa6ed2e commit 4edd49e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion governance/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ func (api *GovernanceKaiaAPI) GetRewards(num *rpc.BlockNumber) (*reward.RewardSp
}

header := api.chain.GetHeaderByNumber(blockNumber)
txs, receipts := api.chain.GetBlock(header.Hash(), blockNumber).Transactions(), api.chain.GetReceiptsByBlockHash(header.Hash())
block := api.chain.GetBlock(header.Hash(), blockNumber)
if block == nil {
return nil, errors.New("not found block")
}
txs, receipts := block.Transactions(), api.chain.GetReceiptsByBlockHash(header.Hash())
if header == nil {
return nil, fmt.Errorf("the block does not exist (block number: %d)", blockNumber)
}
Expand Down
9 changes: 7 additions & 2 deletions governance/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,15 @@ func (bc *testBlockChain) GetHeaderByNumber(val uint64) *types.Header {
}

func (bc *testBlockChain) GetReceiptsByBlockHash(hash common.Hash) types.Receipts {
return nil
return types.Receipts{
&types.Receipt{GasUsed: 10},
&types.Receipt{GasUsed: 10},
}
}

func (bc *testBlockChain) GetBlockByNumber(num uint64) *types.Block { return nil }
func (bc *testBlockChain) GetBlockByNumber(num uint64) *types.Block {
return types.NewBlockWithHeader(bc.GetHeaderByNumber(num))
}
func (bc *testBlockChain) StateAt(root common.Hash) (*state.StateDB, error) { return nil, nil }
func (bc *testBlockChain) State() (*state.StateDB, error) { return nil, nil }
func (bc *testBlockChain) Config() *params.ChainConfig {
Expand Down
2 changes: 1 addition & 1 deletion node/cn/gasprice/gasprice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func newTestBackend(t *testing.T, magmaBlock, kaiaBlock *big.Int) (*testBackend,
config.KoreCompatibleBlock = kaiaBlock
config.ShanghaiCompatibleBlock = kaiaBlock
config.CancunCompatibleBlock = kaiaBlock
config.KaiaCompatibleBlock = kaiaBlock
// config.KaiaCompatibleBlock = kaiaBlock
config.Governance = params.GetDefaultGovernanceConfig()
config.Istanbul = params.GetDefaultIstanbulConfig()
blocks, _ := blockchain.GenerateChain(gspec.Config, genesis, gxhash.NewFaker(), db, testHead+1, func(i int, b *blockchain.BlockGen) {
Expand Down

0 comments on commit 4edd49e

Please sign in to comment.