Skip to content

Commit

Permalink
rusk: passing nonce and metadata for contract id generation
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed Jul 24, 2024
1 parent a1e59b8 commit 15b009c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions rusk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add support for nonce and metadata in contract deployment [#1884]
- Add execution of contract deployment [#1882]
- Add first version of RUES, allowing websocket clients to subscribe for events
emitted by block transitions [#931]
Expand Down Expand Up @@ -210,6 +211,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add linking between Rusk and Protobuff structs
- Add build system that generates keys for circuits and caches them.

[#1884]: https://github.com/dusk-network/rusk/issues/1884
[#1882]: https://github.com/dusk-network/rusk/issues/1882
[#1675]: https://github.com/dusk-network/rusk/issues/1675
[#1640]: https://github.com/dusk-network/rusk/issues/1640
Expand Down
10 changes: 7 additions & 3 deletions rusk/src/lib/chain/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use node_data::ledger::{Slash, SpentTransaction, Transaction};
use rusk_abi::dusk::Dusk;
use rusk_abi::ContractError::{OutOfGas, Panic};
use rusk_abi::{
CallReceipt, ContractError, Error as PiecrustError, Event, Session,
STAKE_CONTRACT, TRANSFER_CONTRACT, VM,
gen_contract_id, CallReceipt, ContractError, Error as PiecrustError, Event,
Session, STAKE_CONTRACT, TRANSFER_CONTRACT, VM,
};
use rusk_profile::to_rusk_state_id_path;
use tokio::sync::broadcast;
Expand Down Expand Up @@ -540,7 +540,11 @@ fn contract_deploy(
receipt.data = Err(Panic("failed bytecode hash check".into()))
} else {
let result = session.deploy_raw(
None,
Some(gen_contract_id(
&deploy.bytecode.bytes,
deploy.nonce,
&deploy.metadata,
)),
deploy.bytecode.bytes.as_slice(),
deploy.constructor_args.clone(),
deploy.owner.clone(),
Expand Down
13 changes: 10 additions & 3 deletions rusk/tests/services/contract_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rand::prelude::*;
use rand::rngs::StdRng;
use rusk::{Result, Rusk};
use rusk_abi::Error::ContractDoesNotExist;
use rusk_abi::{ContractData, ContractId};
use rusk_abi::{gen_contract_id, ContractData, ContractId};
use rusk_recovery_tools::state;
use tempfile::tempdir;
use test_wallet::{self as wallet, Wallet};
Expand Down Expand Up @@ -78,7 +78,12 @@ fn initial_state<P: AsRef<Path>>(dir: P, deploy_bob: bool) -> Result<Rusk> {
bob_bytecode,
ContractData::builder()
.owner(OWNER)
.constructor_arg(&BOB_INIT_VALUE),
.constructor_arg(&BOB_INIT_VALUE)
.contract_id(gen_contract_id(
&bob_bytecode,
0u64,
vec![],
)),
POINT_LIMIT,
)
.expect("Deploying the alice contract should succeed");
Expand Down Expand Up @@ -122,6 +127,8 @@ fn make_and_execute_transaction_deploy(
},
owner: OWNER.to_vec(),
constructor_args,
nonce: 0,
metadata: vec![],
}),
SENDER_INDEX,
gas_limit,
Expand Down Expand Up @@ -192,7 +199,7 @@ impl Fixture {
"../../../target/dusk/wasm32-unknown-unknown/release/bob.wasm"
)
.to_vec();
let contract_id = bytecode_hash(bob_bytecode.as_slice());
let contract_id = gen_contract_id(&bob_bytecode, 0u64, vec![]);

let path = tmp.into_path();
Self {
Expand Down

0 comments on commit 15b009c

Please sign in to comment.