Skip to content

Commit 0ba7436

Browse files
committed
Fix unit tests
1 parent 56eee8b commit 0ba7436

File tree

4 files changed

+57
-19
lines changed

4 files changed

+57
-19
lines changed

Cargo.lock

Lines changed: 39 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chain/ethereum/src/adapter.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use graph::data_source::common::ContractCall;
77
use graph::firehose::CallToFilter;
88
use graph::firehose::CombinedFilter;
99
use graph::firehose::LogFilter;
10-
use graph::prelude::alloy::primitives::Address;
11-
use graph::prelude::alloy::primitives::B256;
10+
use graph::prelude::alloy::primitives::{Address, B256};
1211
use graph::prelude::alloy::rpc::types::Block as AlloyBlock;
1312
use graph::prelude::alloy::rpc::types::Log;
1413
use graph::prelude::alloy::transports::{RpcError, TransportErrorKind};
@@ -1239,7 +1238,7 @@ mod tests {
12391238
use graph::blockchain::TriggerFilter as _;
12401239
use graph::firehose::{CallToFilter, CombinedFilter, LogFilter, MultiLogFilter};
12411240
use graph::petgraph::graphmap::GraphMap;
1242-
use graph::prelude::alloy::primitives::{Address, Bytes, B256};
1241+
use graph::prelude::alloy::primitives::{Address, Bytes, B256, U256};
12431242
use graph::prelude::EthereumCall;
12441243
use hex::ToHex;
12451244
use itertools::Itertools;
@@ -1324,7 +1323,7 @@ mod tests {
13241323

13251324
#[test]
13261325
fn ethereum_trigger_filter_to_firehose() {
1327-
let sig = |value: u64| B256::from_slice(&value.to_le_bytes());
1326+
let sig = |value: u64| B256::from(U256::from(value));
13281327
let mut filter = TriggerFilter {
13291328
log: EthereumLogFilter {
13301329
contracts_and_events_graph: GraphMap::new(),
@@ -1446,8 +1445,8 @@ mod tests {
14461445

14471446
#[test]
14481447
fn ethereum_trigger_filter_to_firehose_every_block_plus_logfilter() {
1449-
let address = |value: u64| Address::from_slice(&value.to_le_bytes());
1450-
let sig = |value: u64| B256::from_slice(&value.to_le_bytes());
1448+
let address = |value: u64| Address::left_padding_from(&value.to_le_bytes());
1449+
let sig = |value: u64| B256::left_padding_from(&value.to_le_bytes());
14511450
let mut filter = TriggerFilter {
14521451
log: EthereumLogFilter {
14531452
contracts_and_events_graph: GraphMap::new(),
@@ -1792,7 +1791,7 @@ mod tests {
17921791
}
17931792

17941793
fn address(value: u64) -> Address {
1795-
Address::from_slice(&value.to_le_bytes())
1794+
Address::left_padding_from(&value.to_be_bytes())
17961795
}
17971796

17981797
fn bytes(value: Vec<u8>) -> Bytes {
@@ -1866,8 +1865,8 @@ fn complete_log_filter() {
18661865

18671866
#[test]
18681867
fn log_filter_require_transacion_receipt_method() {
1869-
let address = |value: u64| Address::from_slice(&value.to_le_bytes());
1870-
let b256 = |value: u64| B256::from_slice(&value.to_le_bytes());
1868+
let address = |value: u64| Address::left_padding_from(&value.to_be_bytes());
1869+
let b256 = |value: u64| B256::left_padding_from(&value.to_be_bytes());
18711870

18721871
// test data
18731872
let event_signature_a = b256(0);

graph/src/components/ethereum/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ impl LightEthereumBlockExt for AlloyBlock {
8787
fn parent_ptr(&self) -> Option<BlockPtr> {
8888
match self.header.number {
8989
0 => None,
90-
n => Some(BlockPtr::new(
91-
self.header.parent_hash.into(),
92-
(n - 1) as i32,
93-
)),
90+
n => {
91+
let number = i32::try_from(n - 1).unwrap();
92+
Some(BlockPtr::new(self.header.parent_hash.into(), number))
93+
}
9494
}
9595
}
9696

tests/src/fixture/ethereum.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ pub fn empty_block(parent_ptr: BlockPtr, ptr: BlockPtr) -> BlockWithTriggers<Cha
122122
create_dummy_transaction(ptr.number as u64, ptr.hash.as_b256(), Some(0), B256::ZERO);
123123
let transactions = BlockTransactions::Full(vec![dummy_txn]);
124124
let alloy_block = create_minimal_block_for_test(ptr.number as u64, ptr.hash.as_b256())
125+
.map_header(|mut header| {
126+
// Ensure the parent hash matches the given parent_ptr so that parent_ptr() lookups succeed
127+
header.inner.parent_hash = parent_ptr.hash.as_b256();
128+
header
129+
})
125130
.with_transactions(transactions);
126131

127132
BlockWithTriggers::<graph_chain_ethereum::Chain> {
@@ -196,7 +201,7 @@ pub fn push_test_command(
196201
inner: alloy::primitives::Log {
197202
address: Address::ZERO,
198203
data: LogData::new_unchecked(
199-
vec![tiny_keccak::keccak256(b"TestEvent(string)").into()],
204+
vec![tiny_keccak::keccak256(b"TestEvent(string,string)").into()],
200205
abi::DynSolValue::Tuple(vec![
201206
abi::DynSolValue::String(test_command.into()),
202207
abi::DynSolValue::String(data.into()),

0 commit comments

Comments
 (0)