fix: EthAPI: Correctly get parent hash

This commit is contained in:
Aayush 2023-03-03 16:42:57 -05:00 committed by Jennifer Wang
parent 1631c6ac8d
commit a59e1d5220
2 changed files with 23 additions and 5 deletions

View File

@ -87,3 +87,25 @@ func TestFilecoinAddressToEthAddress(t *testing.T) {
require.ErrorContains(t, err, ethtypes.ErrInvalidAddress.Error()) require.ErrorContains(t, err, ethtypes.ErrInvalidAddress.Error())
} }
func TestEthGetGenesis(t *testing.T) {
blockTime := 100 * time.Millisecond
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC())
ens.InterconnectAll().BeginMining(blockTime)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
ethBlk, err := client.EVM().EthGetBlockByNumber(ctx, "0x0", true)
require.NoError(t, err)
genesis, err := client.ChainGetGenesis(ctx)
require.NoError(t, err)
genesisCid, err := genesis.Key().Cid()
require.NoError(t, err)
genesisHash, err := ethtypes.EthHashFromCid(genesisCid)
require.NoError(t, err)
require.Equal(t, ethBlk.Hash, genesisHash)
}

View File

@ -1763,11 +1763,7 @@ func (e *ethSubscription) stop() {
} }
func newEthBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTxInfo bool, cs *store.ChainStore, sa StateAPI) (ethtypes.EthBlock, error) { func newEthBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTxInfo bool, cs *store.ChainStore, sa StateAPI) (ethtypes.EthBlock, error) {
parent, err := cs.LoadTipSet(ctx, ts.Parents()) parentKeyCid, err := ts.Parents().Cid()
if err != nil {
return ethtypes.EthBlock{}, err
}
parentKeyCid, err := parent.Key().Cid()
if err != nil { if err != nil {
return ethtypes.EthBlock{}, err return ethtypes.EthBlock{}, err
} }