Skip to content

Commit

Permalink
Merge pull request #3430 from dusk-network/execution_config
Browse files Browse the repository at this point in the history
vm: Change `execution` module to use `execution::Config`
  • Loading branch information
herr-seppia authored Jan 28, 2025
2 parents caa4aad + 39ddca2 commit 0082152
Show file tree
Hide file tree
Showing 29 changed files with 328 additions and 207 deletions.
30 changes: 17 additions & 13 deletions contracts/stake/tests/partial_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use dusk_core::signatures::bls::{
};
use dusk_core::stake::{Reward, RewardReason, EPOCH, STAKE_CONTRACT};
use dusk_core::transfer::TRANSFER_CONTRACT;
use dusk_vm::{execute, ContractData, Error as VMError, Session, VM};
use dusk_vm::{
execute, ContractData, Error as VMError, ExecutionConfig, Session, VM,
};
use rand::rngs::StdRng;
use rand::SeedableRng;
use wallet_core::transaction::{
Expand All @@ -26,6 +28,8 @@ const GENESIS_VALUE: u64 = dusk(1_000_000.0);
const STAKE_VALUE: u64 = GENESIS_VALUE / 2;
const GENESIS_NONCE: u64 = 0;

const NO_CONFIG: ExecutionConfig = ExecutionConfig::DEFAULT;

#[test]
fn stake() -> Result<(), VMError> {
// ------
Expand Down Expand Up @@ -59,7 +63,7 @@ fn stake() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
let receipt = execute(&mut session, &tx, 0, 0, 0)?;
let receipt = execute(&mut session, &tx, &NO_CONFIG)?;

// verify 1st stake transaction
let gas_spent_1 = receipt.gas_spent;
Expand Down Expand Up @@ -87,7 +91,7 @@ fn stake() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
let receipt = execute(&mut session, &tx, 0, 0, 0)?;
let receipt = execute(&mut session, &tx, &NO_CONFIG)?;

// verify 2nd stake transaction
let gas_spent_2 = receipt.gas_spent;
Expand Down Expand Up @@ -121,7 +125,7 @@ fn stake() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
let receipt = execute(&mut session, &tx, 0, 0, 0)?;
let receipt = execute(&mut session, &tx, &NO_CONFIG)?;

// verify 3rd stake transaction
let gas_spent_3 = receipt.gas_spent;
Expand Down Expand Up @@ -156,7 +160,7 @@ fn stake() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
assert!(execute(&mut session, &tx, 0, 0, 0).is_err());
assert!(execute(&mut session, &tx, &NO_CONFIG).is_err());

Ok(())
}
Expand Down Expand Up @@ -190,7 +194,7 @@ fn unstake() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
let receipt = execute(&mut session, &tx, 0, 0, 0)?;
let receipt = execute(&mut session, &tx, &NO_CONFIG)?;
let mut moonlight_balance = GENESIS_VALUE - STAKE_VALUE - receipt.gas_spent;
assert_moonlight(&mut session, &moonlight_pk, moonlight_balance, nonce);

Expand All @@ -212,7 +216,7 @@ fn unstake() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
let receipt = execute(&mut session, &tx, 0, 0, 0)?;
let receipt = execute(&mut session, &tx, &NO_CONFIG)?;

// verify 1st unstake transaction
let gas_spent_1 = receipt.gas_spent;
Expand Down Expand Up @@ -242,7 +246,7 @@ fn unstake() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
let receipt = execute(&mut session, &tx, 0, 0, 0)?;
let receipt = execute(&mut session, &tx, &NO_CONFIG)?;
total_stake = STAKE_VALUE;
let mut locked = unstake_1 / 10;
assert_stake(&mut session, &stake_pk, total_stake, locked, 0);
Expand All @@ -268,7 +272,7 @@ fn unstake() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
let receipt = execute(&mut session, &tx, 0, 0, 0)?;
let receipt = execute(&mut session, &tx, &NO_CONFIG)?;

// verify 2nd unstake transaction
let gas_spent_2 = receipt.gas_spent;
Expand Down Expand Up @@ -306,7 +310,7 @@ fn unstake() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
let receipt = execute(&mut session, &tx, 0, 0, 0)?;
let receipt = execute(&mut session, &tx, &NO_CONFIG)?;

// verify 3rd unstake transaction
let gas_spent_3 = receipt.gas_spent;
Expand Down Expand Up @@ -349,7 +353,7 @@ fn withdraw_reward() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
let receipt = execute(&mut session, &tx, 0, 0, 0)?;
let receipt = execute(&mut session, &tx, &NO_CONFIG)?;
let mut moonlight_balance = GENESIS_VALUE - STAKE_VALUE - receipt.gas_spent;
assert_moonlight(&mut session, &moonlight_pk, moonlight_balance, nonce);
// add a reward to the staked key
Expand All @@ -374,7 +378,7 @@ fn withdraw_reward() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
let receipt = execute(&mut session, &tx, 0, 0, 0)?;
let receipt = execute(&mut session, &tx, &NO_CONFIG)?;

// verify 1st reward withdrawal
let gas_spent_1 = receipt.gas_spent;
Expand Down Expand Up @@ -409,7 +413,7 @@ fn withdraw_reward() -> Result<(), VMError> {
CHAIN_ID,
)
.expect("tx creation should pass");
let receipt = execute(&mut session, &tx, 0, 0, 0)?;
let receipt = execute(&mut session, &tx, &NO_CONFIG)?;

// verify 1st reward withdrawal
let gas_spent_2 = receipt.gas_spent;
Expand Down
10 changes: 6 additions & 4 deletions contracts/stake/tests/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use dusk_core::transfer::withdraw::{
Withdraw, WithdrawReceiver, WithdrawReplayToken,
};
use dusk_core::{dusk, JubJubScalar};
use dusk_vm::{execute, VM};
use dusk_vm::{execute, ExecutionConfig, VM};
use ff::Field;
use rand::rngs::StdRng;
use rand::SeedableRng;
Expand All @@ -34,6 +34,8 @@ use crate::common::utils::*;
const GENESIS_VALUE: u64 = dusk(1_000_000.0);
const INITIAL_STAKE: u64 = GENESIS_VALUE / 2;

const NO_CONFIG: ExecutionConfig = ExecutionConfig::DEFAULT;

#[test]
fn stake_withdraw_unstake() {
// ------
Expand Down Expand Up @@ -85,7 +87,7 @@ fn stake_withdraw_unstake() {
contract_call,
);

let receipt = execute(&mut session, &tx, 0, 0, 0)
let receipt = execute(&mut session, &tx, &NO_CONFIG)
.expect("Executing TX should succeed");

let gas_spent = receipt.gas_spent;
Expand Down Expand Up @@ -181,7 +183,7 @@ fn stake_withdraw_unstake() {
.session(base, CHAIN_ID, 2)
.expect("Instantiating new session should succeed");

let receipt = execute(&mut session, &tx, 0, 0, 0)
let receipt = execute(&mut session, &tx, &NO_CONFIG)
.expect("Executing TX should succeed");

let gas_spent = receipt.gas_spent;
Expand Down Expand Up @@ -278,7 +280,7 @@ fn stake_withdraw_unstake() {
.session(base, CHAIN_ID, 3)
.expect("Instantiating new session should succeed");

let receipt = execute(&mut session, &tx, 0, 0, 0)
let receipt = execute(&mut session, &tx, &NO_CONFIG)
.expect("Executing TX should succeed");
update_root(&mut session).expect("Updating the root should succeed");

Expand Down
26 changes: 14 additions & 12 deletions contracts/transfer/tests/moonlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use dusk_core::transfer::{
ContractToAccount, ContractToContract, Transaction, TRANSFER_CONTRACT,
};
use dusk_core::{dusk, JubJubScalar, LUX};
use dusk_vm::{execute, ContractData, Session, VM};
use dusk_vm::{execute, ContractData, ExecutionConfig, Session, VM};
use ff::Field;
use rand::rngs::StdRng;
use rand::SeedableRng;
Expand Down Expand Up @@ -52,6 +52,8 @@ const BOB_ID: ContractId = {
const OWNER: [u8; 32] = [0; 32];
const CHAIN_ID: u8 = 0xFA;

const NO_CONFIG: ExecutionConfig = ExecutionConfig::DEFAULT;

/// Instantiate the virtual machine with the transfer contract deployed, with a
/// moonlight account owning the `MOONLIGHT_GENESIS_VALUE` and alice and bob
/// contracts deployed with alice contract owning `ALICE_GENESIS_VALUE`.
Expand Down Expand Up @@ -183,7 +185,7 @@ fn transfer() {
)
.expect("Creating moonlight transaction should succeed");

let gas_spent = execute(session, &transaction, 0, 0, 0)
let gas_spent = execute(session, &transaction, &NO_CONFIG)
.expect("Transaction should succeed")
.gas_spent;

Expand Down Expand Up @@ -248,7 +250,7 @@ fn transfer_with_refund() {
.into();

let max_gas = GAS_LIMIT * LUX;
let gas_spent = execute(session, &transaction, 0, 0, 0)
let gas_spent = execute(session, &transaction, &NO_CONFIG)
.expect("Transaction should succeed")
.gas_spent;
let gas_refund = max_gas - gas_spent;
Expand Down Expand Up @@ -313,7 +315,7 @@ fn transfer_gas_fails() {
)
.expect("Creating moonlight transaction should succeed");

let result = execute(session, &transaction, 0, 0, 0);
let result = execute(session, &transaction, &NO_CONFIG);

assert!(
result.is_err(),
Expand Down Expand Up @@ -365,7 +367,7 @@ fn alice_ping() {
)
.expect("Creating moonlight transaction should succeed");

let gas_spent = execute(session, &transaction, 0, 0, 0)
let gas_spent = execute(session, &transaction, &NO_CONFIG)
.expect("Transaction should succeed")
.gas_spent;

Expand Down Expand Up @@ -446,7 +448,7 @@ fn convert_to_phoenix() {
)
.expect("Creating moonlight transaction should succeed");

let gas_spent = execute(&mut session, &tx, 0, 0, 0)
let gas_spent = execute(&mut session, &tx, &NO_CONFIG)
.expect("Executing transaction should succeed")
.gas_spent;
update_root(session).expect("Updating the root should succeed");
Expand Down Expand Up @@ -566,7 +568,7 @@ fn convert_to_moonlight_fails() {
)
.expect("Creating moonlight transaction should succeed");

let receipt = execute(&mut session, &tx, 0, 0, 0)
let receipt = execute(&mut session, &tx, &NO_CONFIG)
.expect("Executing TX should succeed");

// check that the transaction execution panicked with the correct message
Expand Down Expand Up @@ -672,7 +674,7 @@ fn convert_wrong_contract_targeted() {
)
.expect("Creating moonlight transaction should succeed");

let receipt = execute(&mut session, &tx, 0, 0, 0)
let receipt = execute(&mut session, &tx, &NO_CONFIG)
.expect("Executing transaction should succeed");
update_root(session).expect("Updating the root should succeed");

Expand Down Expand Up @@ -744,7 +746,7 @@ fn contract_to_contract() {
)
.expect("Creating moonlight transaction should succeed");

let receipt = execute(session, &transaction, 0, 0, 0)
let receipt = execute(session, &transaction, &NO_CONFIG)
.expect("Transaction should succeed");
let gas_spent = receipt.gas_spent;

Expand Down Expand Up @@ -811,7 +813,7 @@ fn contract_to_account() {
)
.expect("Creating moonlight transaction should succeed");

let receipt = execute(session, &transaction, 0, 0, 0)
let receipt = execute(session, &transaction, &NO_CONFIG)
.expect("Transaction should succeed");
let gas_spent = receipt.gas_spent;

Expand Down Expand Up @@ -875,7 +877,7 @@ fn contract_to_account_insufficient_funds() {
)
.expect("Creating moonlight transaction should succeed");

let receipt = execute(session, &transaction, 0, 0, 0)
let receipt = execute(session, &transaction, &NO_CONFIG)
.expect("Transaction should succeed");
let gas_spent = receipt.gas_spent;

Expand Down Expand Up @@ -946,7 +948,7 @@ fn contract_to_account_direct_call() {
)
.expect("Creating moonlight transaction should succeed");

let receipt = execute(session, &transaction, 0, 0, 0)
let receipt = execute(session, &transaction, &NO_CONFIG)
.expect("Transaction should succeed");
let gas_spent = receipt.gas_spent;

Expand Down
Loading

0 comments on commit 0082152

Please sign in to comment.