Skip to content

Commit

Permalink
Merge branch 'feat-2.0' into update-wasm-lanes
Browse files Browse the repository at this point in the history
 Conflicts:
	execution_engine_testing/tests/src/test/explorer/faucet.rs
  • Loading branch information
mpapierski committed Dec 16, 2024
2 parents b6424a7 + 1284982 commit 98fa200
Show file tree
Hide file tree
Showing 27 changed files with 525 additions and 2,332 deletions.
1,198 changes: 170 additions & 1,028 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ lint-smart-contracts:

.PHONY: audit-rs
audit-rs:
$(CARGO) audit --ignore RUSTSEC-2024-0344 --ignore RUSTSEC-2024-0367 --ignore RUSTSEC-2024-0371 --ignore RUSTSEC-2024-0421
$(CARGO) audit

.PHONY: audit-as
audit-as:
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ wat = "1.220.0"
[dev-dependencies]
assert_matches = "1.3.0"
casper-types = { path = "../types", features = ["datasize", "json-schema", "testing", "std"] }
criterion = "0.3.5"
criterion = "0.5.1"
proptest = "1.0.0"
tempfile = "3.4.0"
walrus = "0.20.2"
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/runtime_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ where
| StoredValue::ContractWasm(_)
| StoredValue::MessageTopic(_)
| StoredValue::Message(_)
| StoredValue::Prepaid(_)
| StoredValue::Prepayment(_)
| StoredValue::EntryPoint(_)
| StoredValue::RawBytes(_) => Ok(()),
}
Expand Down
2 changes: 1 addition & 1 deletion execution_engine_testing/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ walrus = "0.20.2"

[dev-dependencies]
assert_matches = "1.3.0"
criterion = { version = "0.3.5", features = ["html_reports"]}
criterion = { version = "0.5.1", features = ["html_reports"]}
dictionary = { path = "../../smart_contracts/contracts/test/dictionary", default-features = false }
dictionary-call = { path = "../../smart_contracts/contracts/test/dictionary-call", default-features = false }
get-call-stack-recursive-subcall = { path = "../../smart_contracts/contracts/test/get-call-stack-recursive-subcall", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion execution_engine_testing/tests/src/test/explorer/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ fn faucet_costs() {
// This test will fail if execution costs vary. The expected costs should not be updated
// without understanding why the cost has changed. If the costs do change, it should be
// reflected in the "Costs by Entry Point" section of the faucet crate's README.md.
const EXPECTED_FAUCET_INSTALL_COST: u64 = 145_436_440_703;
const EXPECTED_FAUCET_INSTALL_COST: u64 = 145_418_559_311;

const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 79_611_645;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use casper_engine_test_support::{
use casper_types::{
runtime_args,
system::auction::{
BidAddr, BidKind, BidsExt, DelegationRate, DelegatorKind, EraInfo, ValidatorBid,
ARG_AMOUNT, ARG_NEW_VALIDATOR, ARG_VALIDATOR,
BidAddr, BidKind, BidsExt, DelegationRate, DelegatorBid, DelegatorKind, EraInfo,
ValidatorBid, ARG_AMOUNT, ARG_NEW_VALIDATOR, ARG_VALIDATOR,
},
GenesisAccount, GenesisValidator, Key, Motes, PublicKey, SecretKey, StoredValue, U512,
};
Expand Down Expand Up @@ -62,6 +62,7 @@ fn should_support_contract_staking() {
let stake = "STAKE".to_string();
let unstake = "UNSTAKE".to_string();
let restake = "RESTAKE".to_string();
let get_staked_amount = "STAKED_AMOUNT".to_string();
let account = *DEFAULT_ACCOUNT_ADDR;
let seed_amount = U512::from(10_000_000_000_000_000_u64);
let delegate_amount = U512::from(5_000_000_000_000_000_u64);
Expand Down Expand Up @@ -153,6 +154,31 @@ fn should_support_contract_staking() {
let pre_delegation_balance = builder.get_purse_balance(contract_purse);
assert_eq!(pre_delegation_balance, seed_amount);

// check delegated amount from contract
builder
.exec(
ExecuteRequestBuilder::contract_call_by_name(
account,
&contract_name,
&entry_point_name,
runtime_args! {
ARG_ACTION => get_staked_amount.clone(),
ARG_VALIDATOR => validator_pk.clone(),
},
)
.build(),
)
.commit()
.expect_success();

let result = builder.get_last_exec_result().unwrap();
let staked_amount: U512 = result.ret().unwrap().to_owned().into_t().unwrap();
assert_eq!(
staked_amount,
U512::zero(),
"staked amount should be zero prior to staking"
);

// stake from contract
builder
.exec(
Expand Down Expand Up @@ -200,6 +226,30 @@ fn should_support_contract_staking() {
);
}

// check delegated amount from contract
builder
.exec(
ExecuteRequestBuilder::contract_call_by_name(
account,
&contract_name,
&entry_point_name,
runtime_args! {
ARG_ACTION => get_staked_amount.clone(),
ARG_VALIDATOR => validator_pk.clone(),
},
)
.build(),
)
.commit()
.expect_success();

let result = builder.get_last_exec_result().unwrap();
let staked_amount: U512 = result.ret().unwrap().to_owned().into_t().unwrap();
assert_eq!(
staked_amount, delegate_amount,
"staked amount should match delegation amount"
);

for _ in 0..=auction_delay {
// crank era
builder.run_auction(timestamp_millis, vec![]);
Expand Down Expand Up @@ -485,3 +535,121 @@ fn should_not_enforce_max_spending_when_main_purse_not_in_use() {
.query(None, delegation_key, &[])
.expect("should have delegation bid");
}

#[ignore]
#[test]
fn should_read_bid_with_vesting_schedule_populated() {
const ARG_ACTION: &str = "action";
let purse_name = "staking_purse".to_string();
let contract_name = "staking".to_string();
let entry_point_name = "run".to_string();
let get_staked_amount = "STAKED_AMOUNT".to_string();
let account = *DEFAULT_ACCOUNT_ADDR;
let seed_amount = U512::from(10_000_000_000_000_000_u64);
let validator_pk = &*DEFAULT_PROPOSER_PUBLIC_KEY;

let mut builder = LmdbWasmTestBuilder::default();
let mut genesis_request = LOCAL_GENESIS_REQUEST.clone();
genesis_request.set_enable_entity(false);
genesis_request.push_genesis_validator(
validator_pk,
GenesisValidator::new(
Motes::new(10_000_000_000_000_000_u64),
DelegationRate::zero(),
),
);
builder.run_genesis(genesis_request);

builder
.exec(
ExecuteRequestBuilder::standard(
account,
STORED_STAKING_CONTRACT_NAME,
runtime_args! {
ARG_AMOUNT => seed_amount
},
)
.build(),
)
.commit()
.expect_success();

let default_account = builder.get_account(account).expect("should have account");
let named_keys = default_account.named_keys();

let contract_key = named_keys
.get(&contract_name)
.expect("contract_name key should exist");

let stored_contract = builder
.query(None, *contract_key, &[])
.expect("should have stored value at contract key");

let contract = stored_contract
.as_contract()
.expect("stored value should be contract");

let contract_named_keys = contract.named_keys();

let contract_purse = contract_named_keys
.get(&purse_name)
.expect("purse_name key should exist")
.into_uref()
.expect("should be a uref");

// Create a mock bid with a vesting schedule initialized.
// This is only there to make sure size constraints are not a problem
// when trying to read this relatively large structure as a guest.
let mut mock_bid = DelegatorBid::locked(
DelegatorKind::Purse(contract_purse.addr()),
U512::from(100_000_000),
contract_purse,
validator_pk.clone(),
0,
);

mock_bid
.vesting_schedule_mut()
.unwrap()
.initialize_with_schedule(U512::from(100_000_000), 0);

let delegation_key = Key::BidAddr(BidAddr::DelegatedPurse {
validator: validator_pk.to_account_hash(),
delegator: contract_purse.addr(),
});

builder.write_data_and_commit(
[(
delegation_key,
StoredValue::BidKind(BidKind::Delegator(Box::new(mock_bid))),
)]
.iter()
.cloned(),
);

builder
.query(None, delegation_key, &[])
.expect("should have delegation bid")
.as_bid_kind()
.expect("should be bidkind")
.vesting_schedule()
.expect("should have vesting schedule")
.locked_amounts()
.expect("should have locked amounts");

builder
.exec(
ExecuteRequestBuilder::contract_call_by_name(
account,
&contract_name,
&entry_point_name,
runtime_args! {
ARG_ACTION => get_staked_amount.clone(),
ARG_VALIDATOR => validator_pk.clone(),
},
)
.build(),
)
.commit()
.expect_success();
}
14 changes: 5 additions & 9 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ either = { version = "1", features = ["serde"] }
enum-iterator = "0.6.0"
erased-serde = "0.3.18"
fs2 = "0.4.3"
futures = "0.3.5"
futures = "0.3.31"
futures-io = "0.3.5"
hex-buffer-serde = "0.3.0"
hex_fmt = "0.3.0"
hostname = "0.3.0"
http = "0.2.1"
humantime = "2.1.0"
hyper = "0.14.26"
hyper = "0.14.27"
itertools = "0.10.3"
libc = "0.2.66"
linked-hash-map = "0.5.3"
Expand All @@ -53,8 +53,8 @@ num_cpus = "1"
once_cell = "1"
openssl = "0.10.66"
pin-project = "1.0.6"
prometheus = "0.12.0"
quanta = "0.7.2"
prometheus = "0.13.4"
quanta = "0.9.2"
rand = "0.8.3"
rand_chacha = "0.3.0"
regex = "1"
Expand Down Expand Up @@ -96,10 +96,6 @@ wheelbuf = "0.2.0"
casper-executor-wasm = { path = "../executor/wasm" }
casper-executor-wasm-interface = { path = "../executor/wasm-interface" }


[build-dependencies]
vergen = { version = "8.3.2", default-features = false, features = ["git", "gitoxide"] }

[dev-dependencies]
casper-binary-port = { version = "1.0.0", path = "../binary_port", features = ["testing"] }
assert-json-diff = "2.0.1"
Expand All @@ -111,7 +107,7 @@ pretty_assertions = "0.7.2"
proptest = "1.0.0"
proptest-derive = "0.3.0"
rand_core = "0.6.2"
reqwest = { version = "0.11.18", features = ["stream"] }
reqwest = { version = "0.11.27", features = ["stream"] }
tokio = { version = "1", features = ["test-util"] }

[features]
Expand Down
41 changes: 38 additions & 3 deletions node/src/components/transaction_acceptor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ use casper_types::{
Block, BlockV2, CLValue, Chainspec, ChainspecRawBytes, Contract, Deploy, EraId, HashAddr,
InvalidDeploy, InvalidTransaction, InvalidTransactionV1, Package, PricingHandling, PricingMode,
ProtocolVersion, PublicKey, SecretKey, StoredValue, TestBlockBuilder, TimeDiff, Timestamp,
Transaction, TransactionConfig, TransactionRuntimeParams, TransactionV1, URef, U512,
Transaction, TransactionArgs, TransactionConfig, TransactionRuntimeParams, TransactionV1, URef,
U512,
};

use super::*;
Expand Down Expand Up @@ -216,6 +217,7 @@ enum TestScenario {
TooLowGasPriceToleranceForDeploy,
InvalidFields,
InvalidFieldsFromPeer,
InvalidArgumentsKind,
}

impl TestScenario {
Expand Down Expand Up @@ -260,7 +262,8 @@ impl TestScenario {
| TestScenario::InvalidPricingModeForTransactionV1
| TestScenario::TooLowGasPriceToleranceForTransactionV1
| TestScenario::TooLowGasPriceToleranceForDeploy
| TestScenario::InvalidFields => Source::Client,
| TestScenario::InvalidFields
| TestScenario::InvalidArgumentsKind => Source::Client,
}
}

Expand Down Expand Up @@ -623,6 +626,25 @@ impl TestScenario {
.unwrap();
Transaction::from(txn)
}
TestScenario::InvalidArgumentsKind => {
let timestamp = Timestamp::now()
+ Config::default().timestamp_leeway
+ TimeDiff::from_millis(100);
let ttl = TimeDiff::from_seconds(300);
let txn = TransactionV1Builder::new_session(
false,
Bytes::from(vec![1]),
TransactionRuntimeParams::VmCasperV1,
)
.with_transaction_args(TransactionArgs::Bytesrepr(Bytes::from(vec![1, 2, 3])))
.with_chain_name("casper-example")
.with_timestamp(timestamp)
.with_ttl(ttl)
.with_secret_key(&secret_key)
.build()
.unwrap();
Transaction::from(txn)
}
}
}

Expand Down Expand Up @@ -681,6 +703,7 @@ impl TestScenario {
TestScenario::TooLowGasPriceToleranceForDeploy => false,
TestScenario::InvalidFields => false,
TestScenario::InvalidFieldsFromPeer => false,
TestScenario::InvalidArgumentsKind => false,
}
}

Expand Down Expand Up @@ -1240,7 +1263,8 @@ async fn run_transaction_acceptor_without_timeout(
| TestScenario::FromClientExpired(_)
| TestScenario::TooLowGasPriceToleranceForTransactionV1
| TestScenario::TooLowGasPriceToleranceForDeploy
| TestScenario::InvalidFields => {
| TestScenario::InvalidFields
| TestScenario::InvalidArgumentsKind => {
matches!(
event,
Event::TransactionAcceptorAnnouncement(
Expand Down Expand Up @@ -2511,3 +2535,14 @@ async fn should_reject_transaction_from_peer_with_unexpected_fields() {
)))
))
}

#[tokio::test]
async fn should_reject_transaction_with_invalid_transaction_args() {
let result = run_transaction_acceptor(TestScenario::InvalidArgumentsKind).await;
assert!(matches!(
result,
Err(super::Error::InvalidTransaction(InvalidTransaction::V1(
InvalidTransactionV1::ExpectedNamedArguments
)))
));
}
Loading

0 comments on commit 98fa200

Please sign in to comment.