Skip to content

Commit c6c6f33

Browse files
committed
refactor: migrate to WIT generation macro in counter-contract example,
run `cargo update`, update miden-node to v0.12.2 in the local network tests.
1 parent 70594ae commit c6c6f33

File tree

14 files changed

+391
-276
lines changed

14 files changed

+391
-276
lines changed

Cargo.lock

Lines changed: 266 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/counter-contract/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ crate-type = ["cdylib"]
1212
[dependencies]
1313
miden = { path = "../../sdk/sdk" }
1414

15-
# [package.metadata.component]
16-
# package = "miden:counter-contract"
15+
[package.metadata.component]
16+
package = "miden:counter-contract"
1717

1818
[package.metadata.miden]
1919
project-kind = "account"

examples/counter-contract/src/lib.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
use miden::{component, felt, Felt, StorageMap, StorageMapAccess, Word};
1010

11-
use crate::bindings::exports::miden::counter_contract::counter::Guest;
12-
13-
miden::generate!();
14-
bindings::export!(CounterContract);
15-
1611
/// Main contract structure for the counter example.
1712
#[component]
1813
struct CounterContract {
@@ -21,29 +16,20 @@ struct CounterContract {
2116
count_map: StorageMap,
2217
}
2318

24-
impl Guest for CounterContract {
19+
#[component]
20+
impl CounterContract {
2521
/// Returns the current counter value stored in the contract's storage map.
26-
fn get_count() -> Felt {
27-
// Get the instance of the contract
28-
let contract = CounterContract::default();
29-
// Define a fixed key for the counter value within the map
22+
pub fn get_count(&self) -> Felt {
3023
let key = Word::from([felt!(0), felt!(0), felt!(0), felt!(1)]);
31-
// Read the value associated with the key from the storage map
32-
contract.count_map.get(&key)
24+
self.count_map.get(&key)
3325
}
3426

3527
/// Increments the counter value stored in the contract's storage map by one.
36-
fn increment_count() -> Felt {
37-
// Get the instance of the contract
38-
let contract = CounterContract::default();
39-
// Define the same fixed key
28+
pub fn increment_count(&self) -> Felt {
4029
let key = Word::from([felt!(0), felt!(0), felt!(0), felt!(1)]);
41-
// Read the current value
42-
let current_value: Felt = contract.count_map.get(&key);
43-
// Increment the value by one
30+
let current_value: Felt = self.count_map.get(&key);
4431
let new_value = current_value + felt!(1);
45-
// Write the new value back to the storage map
46-
contract.count_map.set(key, new_value);
32+
self.count_map.set(key, new_value);
4733
new_value
4834
}
4935
}

examples/counter-contract/wit/counter.wit

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/counter-note/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ package = "miden:counter-note"
2727
"miden:counter-contract" = { path = "../counter-contract" }
2828

2929
[package.metadata.component.target.dependencies]
30-
"miden:counter-contract" = { path = "../counter-contract/wit/counter.wit" }
30+
"miden:counter-account" = { path = "../counter-contract/target/generated-wit/" }
31+
3132

3233
[profile.release]
3334
trim-paths = ["diagnostics", "object"]

examples/counter-note/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
use miden::*;
1111

12-
use crate::bindings::miden::counter_contract::counter;
12+
use crate::bindings::miden::counter_contract::counter_contract;
1313

1414
#[note_script]
1515
fn run(_arg: Word) {
16-
let initial_value = counter::get_count();
17-
counter::increment_count();
16+
let initial_value = counter_contract::get_count();
17+
counter_contract::increment_count();
1818
let expected_value = initial_value + Felt::from_u32(1);
19-
let final_value = counter::get_count();
19+
let final_value = counter_contract::get_count();
2020
assert_eq(final_value, expected_value);
2121
}

tests/integration-node/src/local_node/setup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::{process::kill_process, sync::read_pid, COORD_DIR};
1111
// the compatible miden-node version. Both should typically use the same major.minor version.
1212

1313
/// The exact miden-node version that is compatible with the miden-client version used in tests
14-
const MIDEN_NODE_VERSION: &str = "0.12.0";
14+
const MIDEN_NODE_VERSION: &str = "0.12.2";
1515

1616
/// Manages the lifecycle of a local Miden node instance
1717
pub struct LocalMidenNode;

tests/integration-node/src/node_tests/counter_contract.rs

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -100,28 +100,8 @@ pub fn test_counter_contract_local() {
100100
.build()
101101
.unwrap();
102102

103-
let tx_result = client
104-
.execute_transaction(counter_account.id(), note_request)
105-
.await
106-
.map_err(|e| {
107-
eprintln!("Transaction creation error: {e}");
108-
e
109-
})
110-
.unwrap();
111-
let executed_transaction = tx_result.executed_transaction();
112-
// dbg!(executed_transaction.output_notes());
113-
114-
assert_eq!(executed_transaction.output_notes().num_notes(), 1);
115-
116-
let executed_tx_output_note = executed_transaction.output_notes().get_note(0);
117-
assert_eq!(executed_tx_output_note.id(), counter_note.id());
118-
let create_note_tx_id = executed_transaction.id();
119-
let proven_tx = client.prove_transaction(&tx_result).await.unwrap();
120-
let submission_height = client
121-
.submit_proven_transaction(proven_tx, tx_result.tx_inputs().clone())
122-
.await
123-
.unwrap();
124-
client.apply_transaction(&tx_result, submission_height).await.unwrap();
103+
let create_note_tx_id =
104+
client.submit_new_transaction(counter_account.id(), note_request).await.unwrap();
125105
eprintln!("Created counter note tx: {create_note_tx_id:?}");
126106

127107
// Consume the note to increment the counter
@@ -130,25 +110,10 @@ pub fn test_counter_contract_local() {
130110
.build()
131111
.unwrap();
132112

133-
let tx_result = client
134-
.execute_transaction(counter_account.id(), consume_request)
135-
.await
136-
.map_err(|e| {
137-
eprintln!("Note consumption transaction error: {e}");
138-
e
139-
})
140-
.unwrap();
141-
eprintln!(
142-
"Consumed counter note tx: https://testnet.midenscan.com/tx/{:?}",
143-
&tx_result.executed_transaction().id()
144-
);
145-
146-
let proven_tx = client.prove_transaction(&tx_result).await.unwrap();
147-
let submission_height = client
148-
.submit_proven_transaction(proven_tx, tx_result.tx_inputs().clone())
113+
let _consume_tx_id = client
114+
.submit_new_transaction(counter_account.id(), consume_request)
149115
.await
150116
.unwrap();
151-
client.apply_transaction(&tx_result, submission_height).await.unwrap();
152117

153118
let sync_result = client.sync_state().await.unwrap();
154119
eprintln!("Synced to block: {}", sync_result.block_num);

0 commit comments

Comments
 (0)