Skip to content

Commit ada5a7e

Browse files
committed
test_vm: drop usage of the Cbor trait
1 parent 5077e82 commit ada5a7e

19 files changed

+201
-160
lines changed

test_vm/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl<'bs> VM<'bs> {
185185
Address::new_bls(VERIFREG_ROOT_KEY).unwrap(),
186186
TokenAmount::zero(),
187187
METHOD_SEND,
188-
RawBytes::default(),
188+
None::<RawBytes>,
189189
)
190190
.unwrap();
191191
let verifreg_root_signer =
@@ -208,10 +208,10 @@ impl<'bs> VM<'bs> {
208208
INIT_ACTOR_ADDR,
209209
TokenAmount::zero(),
210210
fil_actor_init::Method::Exec as u64,
211-
fil_actor_init::ExecParams {
211+
Some(fil_actor_init::ExecParams {
212212
code_cid: *MULTISIG_ACTOR_CODE_ID,
213213
constructor_params: msig_ctor_params,
214-
},
214+
}),
215215
)
216216
.unwrap()
217217
.ret
@@ -247,7 +247,7 @@ impl<'bs> VM<'bs> {
247247
Address::new_bls(FAUCET_ROOT_KEY).unwrap(),
248248
faucet_total,
249249
METHOD_SEND,
250-
RawBytes::default(),
250+
None::<RawBytes>,
251251
)
252252
.unwrap();
253253

@@ -394,13 +394,13 @@ impl<'bs> VM<'bs> {
394394
self.curr_epoch
395395
}
396396

397-
pub fn apply_message<C: Cbor>(
397+
pub fn apply_message<S: serde::Serialize>(
398398
&self,
399399
from: Address,
400400
to: Address,
401401
value: TokenAmount,
402402
method: MethodNum,
403-
params: C,
403+
params: Option<S>,
404404
) -> Result<MessageResult, TestVMError> {
405405
let from_id = self.normalize_address(&from).unwrap();
406406
let mut a = self.get_actor(from_id).unwrap();
@@ -423,7 +423,9 @@ impl<'bs> VM<'bs> {
423423
to,
424424
value,
425425
method,
426-
params: serialize(&params, "params for apply message").unwrap(),
426+
params: params.map_or(RawBytes::default(), |p| {
427+
serialize(&p, "params for apply message").unwrap()
428+
}),
427429
};
428430
let mut new_ctx = InvocationCtx {
429431
v: self,

test_vm/src/util.rs

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cmp::min;
33
use frc46_token::receiver::types::{FRC46TokenReceived, UniversalReceiverParams, FRC46_TOKEN_TYPE};
44
use frc46_token::token::types::{BurnParams, TransferFromParams, TransferParams};
55
use fvm_ipld_bitfield::BitField;
6-
use fvm_ipld_encoding::{BytesDe, Cbor, RawBytes};
6+
use fvm_ipld_encoding::{BytesDe, RawBytes};
77
use fvm_shared::address::{Address, BLS_PUB_LEN};
88
use fvm_shared::crypto::signature::{Signature, SignatureType};
99
use fvm_shared::deal::DealID;
@@ -14,6 +14,7 @@ use fvm_shared::sector::{PoStProof, RegisteredPoStProof, RegisteredSealProof, Se
1414
use fvm_shared::{MethodNum, METHOD_SEND};
1515
use rand::prelude::*;
1616
use rand_chacha::ChaCha8Rng;
17+
use serde::Serialize;
1718

1819
use fil_actor_account::Method as AccountMethod;
1920
use fil_actor_cron::Method as CronMethod;
@@ -79,30 +80,30 @@ pub fn create_accounts_seeded(v: &VM, count: u64, balance: TokenAmount, seed: u6
7980
let pk_addrs = pk_addrs_from(seed, count);
8081
// Send funds from faucet to pk address, creating account actor
8182
for pk_addr in pk_addrs.clone() {
82-
apply_ok(v, TEST_FAUCET_ADDR, pk_addr, balance.clone(), METHOD_SEND, RawBytes::default());
83+
apply_ok(v, TEST_FAUCET_ADDR, pk_addr, balance.clone(), METHOD_SEND, None::<RawBytes>);
8384
}
8485
// Normalize pk address to return id address of account actor
8586
pk_addrs.iter().map(|&pk_addr| v.normalize_address(&pk_addr).unwrap()).collect()
8687
}
8788

88-
pub fn apply_ok<C: Cbor>(
89+
pub fn apply_ok<S: Serialize>(
8990
v: &VM,
9091
from: Address,
9192
to: Address,
9293
value: TokenAmount,
9394
method: MethodNum,
94-
params: C,
95+
params: Option<S>,
9596
) -> RawBytes {
9697
apply_code(v, from, to, value, method, params, ExitCode::OK)
9798
}
9899

99-
pub fn apply_code<C: Cbor>(
100+
pub fn apply_code<S: Serialize>(
100101
v: &VM,
101102
from: Address,
102103
to: Address,
103104
value: TokenAmount,
104105
method: MethodNum,
105-
params: C,
106+
params: Option<S>,
106107
code: ExitCode,
107108
) -> RawBytes {
108109
let res = v.apply_message(from, to, value, method, params).unwrap();
@@ -117,7 +118,7 @@ pub fn cron_tick(v: &VM) {
117118
CRON_ACTOR_ADDR,
118119
TokenAmount::zero(),
119120
CronMethod::EpochTick as u64,
120-
RawBytes::default(),
121+
None::<RawBytes>,
121122
);
122123
}
123124

@@ -144,7 +145,7 @@ pub fn create_miner(
144145
STORAGE_POWER_ACTOR_ADDR,
145146
balance,
146147
PowerMethod::CreateMiner as u64,
147-
params,
148+
Some(params),
148149
)
149150
.unwrap()
150151
.ret
@@ -177,7 +178,14 @@ pub fn miner_precommit_sector(
177178
replace_sector_number: 0,
178179
};
179180

180-
apply_ok(v, worker, miner_id, TokenAmount::zero(), MinerMethod::PreCommitSector as u64, params);
181+
apply_ok(
182+
v,
183+
worker,
184+
miner_id,
185+
TokenAmount::zero(),
186+
MinerMethod::PreCommitSector as u64,
187+
Some(params),
188+
);
181189

182190
let state: MinerState = v.get_state(miner_id).unwrap();
183191
state.get_precommitted_sector(v.store, sector_number).unwrap().unwrap()
@@ -191,7 +199,7 @@ pub fn miner_prove_sector(v: &VM, worker: Address, miner_id: Address, sector_num
191199
miner_id,
192200
TokenAmount::zero(),
193201
MinerMethod::ProveCommitSector as u64,
194-
prove_commit_params,
202+
Some(prove_commit_params),
195203
);
196204

197205
ExpectInvocation {
@@ -297,7 +305,7 @@ pub fn precommit_sectors_v2(
297305
maddr,
298306
TokenAmount::zero(),
299307
MinerMethod::PreCommitSectorBatch as u64,
300-
PreCommitSectorBatchParams { sectors: param_sectors.clone() },
308+
Some(PreCommitSectorBatchParams { sectors: param_sectors.clone() }),
301309
);
302310
let expect = ExpectInvocation {
303311
to: mid,
@@ -346,7 +354,7 @@ pub fn precommit_sectors_v2(
346354
maddr,
347355
TokenAmount::zero(),
348356
MinerMethod::PreCommitSectorBatch2 as u64,
349-
PreCommitSectorBatchParams2 { sectors: param_sectors.clone() },
357+
Some(PreCommitSectorBatchParams2 { sectors: param_sectors.clone() }),
350358
);
351359
let expect = ExpectInvocation {
352360
to: mid,
@@ -424,7 +432,7 @@ pub fn prove_commit_sectors(
424432
maddr,
425433
TokenAmount::zero(),
426434
MinerMethod::ProveCommitAggregate as u64,
427-
prove_commit_aggregate_params,
435+
Some(prove_commit_aggregate_params),
428436
);
429437

430438
ExpectInvocation {
@@ -487,7 +495,7 @@ pub fn miner_extend_sector_expiration2(
487495
miner_id,
488496
TokenAmount::zero(),
489497
MinerMethod::ExtendSectorExpiration2 as u64,
490-
extension_params,
498+
Some(extension_params),
491499
);
492500

493501
let mut claim_ids = vec![];
@@ -674,7 +682,7 @@ pub fn declare_recovery(
674682
maddr,
675683
TokenAmount::zero(),
676684
MinerMethod::DeclareFaultsRecovered as u64,
677-
recover_params,
685+
Some(recover_params),
678686
);
679687
}
680688

@@ -696,7 +704,14 @@ pub fn submit_windowed_post(
696704
chain_commit_epoch: dline_info.challenge,
697705
chain_commit_rand: Randomness(TEST_VM_RAND_ARRAY.into()),
698706
};
699-
apply_ok(v, worker, maddr, TokenAmount::zero(), MinerMethod::SubmitWindowedPoSt as u64, params);
707+
apply_ok(
708+
v,
709+
worker,
710+
maddr,
711+
TokenAmount::zero(),
712+
MinerMethod::SubmitWindowedPoSt as u64,
713+
Some(params),
714+
);
700715
let mut subinvocs = None;
701716
if let Some(new_pow) = new_power {
702717
if new_pow == PowerPair::zero() {
@@ -740,7 +755,7 @@ pub fn change_beneficiary(
740755
maddr,
741756
TokenAmount::zero(),
742757
MinerMethod::ChangeBeneficiary as u64,
743-
beneficiary_change_proposal.clone(),
758+
Some(beneficiary_change_proposal.clone()),
744759
);
745760
}
746761

@@ -751,7 +766,7 @@ pub fn get_beneficiary(v: &VM, from: Address, m_addr: Address) -> GetBeneficiary
751766
m_addr,
752767
TokenAmount::zero(),
753768
MinerMethod::GetBeneficiary as u64,
754-
RawBytes::default(),
769+
None::<RawBytes>,
755770
)
756771
.deserialize()
757772
.unwrap()
@@ -764,7 +779,7 @@ pub fn change_owner_address(v: &VM, from: Address, m_addr: Address, new_miner_ad
764779
m_addr,
765780
TokenAmount::zero(),
766781
MinerMethod::ChangeOwnerAddress as u64,
767-
new_miner_addr,
782+
Some(new_miner_addr),
768783
);
769784
}
770785

@@ -782,7 +797,7 @@ pub fn withdraw_balance(
782797
m_addr,
783798
TokenAmount::zero(),
784799
MinerMethod::WithdrawBalance as u64,
785-
params.clone(),
800+
Some(params.clone()),
786801
)
787802
.deserialize()
788803
.unwrap();
@@ -824,7 +839,14 @@ pub fn submit_invalid_post(
824839
chain_commit_epoch: dline_info.challenge,
825840
chain_commit_rand: Randomness(TEST_VM_RAND_ARRAY.into()),
826841
};
827-
apply_ok(v, worker, maddr, TokenAmount::zero(), MinerMethod::SubmitWindowedPoSt as u64, params);
842+
apply_ok(
843+
v,
844+
worker,
845+
maddr,
846+
TokenAmount::zero(),
847+
MinerMethod::SubmitWindowedPoSt as u64,
848+
Some(params),
849+
);
828850
}
829851

830852
pub fn verifreg_add_verifier(v: &VM, verifier: Address, data_cap: StoragePower) {
@@ -843,7 +865,7 @@ pub fn verifreg_add_verifier(v: &VM, verifier: Address, data_cap: StoragePower)
843865
TEST_VERIFREG_ROOT_ADDR,
844866
TokenAmount::zero(),
845867
MultisigMethod::Propose as u64,
846-
proposal,
868+
Some(proposal),
847869
);
848870
ExpectInvocation {
849871
to: TEST_VERIFREG_ROOT_ADDR,
@@ -875,7 +897,7 @@ pub fn verifreg_add_client(v: &VM, verifier: Address, client: Address, allowance
875897
VERIFIED_REGISTRY_ACTOR_ADDR,
876898
TokenAmount::zero(),
877899
VerifregMethod::AddVerifiedClient as u64,
878-
add_client_params,
900+
Some(add_client_params),
879901
);
880902
ExpectInvocation {
881903
to: VERIFIED_REGISTRY_ACTOR_ADDR,
@@ -923,7 +945,7 @@ pub fn verifreg_extend_claim_terms(
923945
VERIFIED_REGISTRY_ACTOR_ADDR,
924946
TokenAmount::zero(),
925947
VerifregMethod::ExtendClaimTerms as u64,
926-
params,
948+
Some(params),
927949
);
928950
}
929951

@@ -942,7 +964,7 @@ pub fn verifreg_remove_expired_allocations(
942964
VERIFIED_REGISTRY_ACTOR_ADDR,
943965
TokenAmount::zero(),
944966
VerifregMethod::RemoveExpiredAllocations as u64,
945-
params,
967+
Some(params),
946968
);
947969
ExpectInvocation {
948970
to: VERIFIED_REGISTRY_ACTOR_ADDR,
@@ -976,7 +998,7 @@ pub fn datacap_get_balance(v: &VM, address: Address) -> TokenAmount {
976998
DATACAP_TOKEN_ACTOR_ADDR,
977999
TokenAmount::zero(),
9781000
DataCapMethod::BalanceOf as u64,
979-
address,
1001+
Some(address),
9801002
);
9811003
deserialize(&ret, "balance of return value").unwrap()
9821004
}
@@ -1007,7 +1029,7 @@ pub fn datacap_extend_claim(
10071029
DATACAP_TOKEN_ACTOR_ADDR,
10081030
TokenAmount::zero(),
10091031
DataCapMethod::Transfer as u64,
1010-
transfer_params,
1032+
Some(transfer_params),
10111033
);
10121034

10131035
ExpectInvocation {
@@ -1061,7 +1083,7 @@ pub fn market_add_balance(v: &VM, sender: Address, beneficiary: Address, amount:
10611083
STORAGE_MARKET_ACTOR_ADDR,
10621084
amount,
10631085
MarketMethod::AddBalance as u64,
1064-
beneficiary,
1086+
Some(beneficiary),
10651087
);
10661088
}
10671089

@@ -1107,7 +1129,7 @@ pub fn market_publish_deal(
11071129
STORAGE_MARKET_ACTOR_ADDR,
11081130
TokenAmount::zero(),
11091131
MarketMethod::PublishStorageDeals as u64,
1110-
publish_params,
1132+
Some(publish_params),
11111133
)
11121134
.deserialize()
11131135
.unwrap();

test_vm/tests/account_authenticate_message_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn account_authenticate_message() {
3333
addr,
3434
TokenAmount::zero(),
3535
AuthenticateMessage as u64,
36-
authenticate_message_params,
36+
Some(authenticate_message_params),
3737
);
3838

3939
// Bad, bad sig! message fails
@@ -45,7 +45,7 @@ fn account_authenticate_message() {
4545
addr,
4646
TokenAmount::zero(),
4747
AuthenticateMessage as u64,
48-
authenticate_message_params,
48+
Some(authenticate_message_params),
4949
ExitCode::USR_ILLEGAL_ARGUMENT,
5050
);
5151
}

test_vm/tests/batch_onboarding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn batch_onboarding(v2: bool) {
150150
CRON_ACTOR_ADDR,
151151
TokenAmount::zero(),
152152
CronMethod::EpochTick as u64,
153-
RawBytes::default(),
153+
None::<RawBytes>,
154154
);
155155

156156
v.expect_state_invariants(

0 commit comments

Comments
 (0)