Skip to content

Commit b2ba9ce

Browse files
committed
tests: Fix warnings from clippy::field_reassign_with_default
1 parent 5e8d469 commit b2ba9ce

2 files changed

Lines changed: 63 additions & 41 deletions

File tree

chain/ethereum/src/codec.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,19 @@ mod test {
526526
#[test]
527527
fn ensure_block_serialization() {
528528
let now = Utc::now().timestamp();
529-
let mut block = Block::default();
530-
let mut header = BlockHeader::default();
531-
header.timestamp = Some(Timestamp {
532-
seconds: now,
533-
nanos: 0,
534-
});
535-
536-
block.header = Some(header);
529+
530+
let header = BlockHeader {
531+
timestamp: Some(Timestamp {
532+
seconds: now,
533+
nanos: 0,
534+
}),
535+
..Default::default()
536+
};
537+
538+
let block = Block {
539+
header: Some(header.clone()),
540+
..Default::default()
541+
};
537542

538543
let str_block = block.data().unwrap().to_string();
539544

chain/ethereum/src/tests.rs

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,31 @@ fn test_trigger_ordering() {
2626
EthereumBlockTriggerType::WithCallTo(Address::random()),
2727
);
2828

29-
let mut call1 = EthereumCall::default();
30-
call1.transaction_index = 1;
29+
let call1 = EthereumCall {
30+
transaction_index: 1,
31+
..Default::default()
32+
};
3133
let call1 = EthereumTrigger::Call(Arc::new(call1));
3234

33-
let mut call2 = EthereumCall::default();
34-
call2.transaction_index = 2;
35-
call2.input = Bytes(vec![0]);
35+
let call2 = EthereumCall {
36+
transaction_index: 2,
37+
input: Bytes(vec![0]),
38+
..Default::default()
39+
};
3640
let call2 = EthereumTrigger::Call(Arc::new(call2));
3741

38-
let mut call3 = EthereumCall::default();
39-
call3.transaction_index = 3;
42+
let call3 = EthereumCall {
43+
transaction_index: 3,
44+
..Default::default()
45+
};
4046
let call3 = EthereumTrigger::Call(Arc::new(call3));
4147

4248
// Call with the same tx index as call2
43-
let mut call4 = EthereumCall::default();
44-
call4.transaction_index = 2;
45-
// different than call2 so they don't get mistaken as the same
46-
call4.input = Bytes(vec![1]);
49+
let call4 = EthereumCall {
50+
transaction_index: 2,
51+
input: Bytes(vec![1]),
52+
..Default::default()
53+
};
4754
let call4 = EthereumTrigger::Call(Arc::new(call4));
4855

4956
fn create_log(tx_index: u64, log_index: u64) -> Arc<Log> {
@@ -92,13 +99,14 @@ fn test_trigger_ordering() {
9299

93100
let logger = Logger::root(slog::Discard, o!());
94101

95-
let mut b: LightEthereumBlock = Default::default();
96-
97-
// This is necessary because inside of BlockWithTriggers::new
98-
// there's a log for both fields. So just using Default above
99-
// gives None on them.
100-
b.number = Some(Default::default());
101-
b.hash = Some(Default::default());
102+
// The field initializers are necessary because inside of
103+
// BlockWithTriggers::new there's a log for both fields. So just using
104+
// Default above gives None on them.
105+
let b: LightEthereumBlock = LightEthereumBlock {
106+
number: Some(Default::default()),
107+
hash: Some(Default::default()),
108+
..Default::default()
109+
};
102110

103111
// Test that `BlockWithTriggers` sorts the triggers.
104112
let block_with_triggers = BlockWithTriggers::<crate::Chain>::new(
@@ -130,21 +138,29 @@ fn test_trigger_dedup() {
130138
// duplicate block2
131139
let block3 = block2.clone();
132140

133-
let mut call1 = EthereumCall::default();
134-
call1.transaction_index = 1;
141+
let call1 = EthereumCall {
142+
transaction_index: 1,
143+
..Default::default()
144+
};
135145
let call1 = EthereumTrigger::Call(Arc::new(call1));
136146

137-
let mut call2 = EthereumCall::default();
138-
call2.transaction_index = 2;
147+
let call2 = EthereumCall {
148+
transaction_index: 2,
149+
..Default::default()
150+
};
139151
let call2 = EthereumTrigger::Call(Arc::new(call2));
140152

141-
let mut call3 = EthereumCall::default();
142-
call3.transaction_index = 3;
153+
let call3 = EthereumCall {
154+
transaction_index: 3,
155+
..Default::default()
156+
};
143157
let call3 = EthereumTrigger::Call(Arc::new(call3));
144158

145159
// duplicate call2
146-
let mut call4 = EthereumCall::default();
147-
call4.transaction_index = 2;
160+
let call4 = EthereumCall {
161+
transaction_index: 2,
162+
..Default::default()
163+
};
148164
let call4 = EthereumTrigger::Call(Arc::new(call4));
149165

150166
fn create_log(tx_index: u64, log_index: u64) -> Arc<Log> {
@@ -190,13 +206,14 @@ fn test_trigger_dedup() {
190206

191207
let logger = Logger::root(slog::Discard, o!());
192208

193-
let mut b: LightEthereumBlock = Default::default();
194-
195-
// This is necessary because inside of BlockWithTriggers::new
196-
// there's a log for both fields. So just using Default above
197-
// gives None on them.
198-
b.number = Some(Default::default());
199-
b.hash = Some(Default::default());
209+
// The field initializers are necessary because inside of
210+
// BlockWithTriggers::new there's a log for both fields. So just using
211+
// Default above gives None on them.
212+
let b: LightEthereumBlock = LightEthereumBlock {
213+
number: Some(Default::default()),
214+
hash: Some(Default::default()),
215+
..Default::default()
216+
};
200217

201218
// Test that `BlockWithTriggers` sorts the triggers.
202219
let block_with_triggers = BlockWithTriggers::<crate::Chain>::new(

0 commit comments

Comments
 (0)