Skip to content

Commit aff7cb5

Browse files
committed
Fix deprecated API usage in test fixtures
- Migrate hello_world and token test fixtures from deprecated events().publish() to #[contractevent] system - Update soroban-token-sdk event usage to use new event structs (Approve, TransferWithAmountOnly, Burn, MintWithAmountOnly) - Fix token Interface implementation to use MuxedAddress for transfer parameter - Add custom SetAdmin event struct for token admin changes This resolves CI build failures on Windows, macOS, and Linux caused by deprecated API warnings being treated as errors.
1 parent a2781a1 commit aff7cb5

2 files changed

Lines changed: 57 additions & 19 deletions

File tree

  • cmd/crates/soroban-test/tests/fixtures/test-wasms

‎cmd/crates/soroban-test/tests/fixtures/test-wasms/hello_world/src/lib.rs‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
#![no_std]
22
use soroban_sdk::{
3-
contract, contractimpl, log, symbol_short, vec, Address, BytesN, Env, String, Symbol, Vec,
3+
contract, contractevent, contractimpl, log, symbol_short, vec, Address, BytesN, Env, String, Symbol, Vec,
44
};
55

66
const COUNTER: Symbol = symbol_short!("COUNTER");
77

8+
#[contractevent]
9+
pub struct AuthEvent {
10+
pub world: Symbol,
11+
}
12+
13+
#[contractevent]
14+
pub struct HelloEvent {
15+
pub str: Symbol,
16+
}
17+
818
#[contract]
919
pub struct Contract;
1020

@@ -25,7 +35,7 @@ impl Contract {
2535
pub fn auth(env: Env, addr: Address, world: Symbol) -> Address {
2636
addr.require_auth();
2737
// Emit test event
28-
env.events().publish(("auth",), world);
38+
AuthEvent { world }.publish(&env);
2939

3040
addr
3141
}
@@ -61,10 +71,7 @@ impl Contract {
6171

6272
/// Logs a string with `hello ` in front.
6373
pub fn log(env: Env, str: Symbol) {
64-
env.events().publish(
65-
(Symbol::new(&env, "hello"), Symbol::new(&env, "")),
66-
str.clone(),
67-
);
74+
HelloEvent { str: str.clone() }.publish(&env);
6875
log!(&env, "hello {}", str);
6976
}
7077
}

‎cmd/crates/soroban-test/tests/fixtures/test-wasms/token/src/contract.rs‎

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
use crate::storage_types::{INSTANCE_BUMP_AMOUNT, INSTANCE_LIFETIME_THRESHOLD};
44
use crate::{admin, allowance, balance, metadata};
55
use soroban_sdk::token::{self, Interface as _};
6-
use soroban_sdk::{contract, contractimpl, Address, Env, String};
6+
use soroban_sdk::{contract, contractevent, contractimpl, Address, Env, MuxedAddress, String};
77
use soroban_token_sdk::metadata::TokenMetadata;
8-
use soroban_token_sdk::TokenUtils;
8+
use soroban_token_sdk::events::{TransferWithAmountOnly, Approve, Burn, MintWithAmountOnly};
9+
10+
#[contractevent(data_format = "single-value")]
11+
pub struct SetAdmin {
12+
#[topic]
13+
admin: Address,
14+
new_admin: Address,
15+
}
916

1017
fn check_nonnegative_amount(amount: i128) {
1118
assert!(amount >= 0, "negative amount is not allowed: {amount}");
@@ -41,7 +48,10 @@ impl Token {
4148
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);
4249

4350
balance::receive(&e, to.clone(), amount);
44-
TokenUtils::new(&e).events().mint(admin, to, amount);
51+
MintWithAmountOnly {
52+
to: to.clone(),
53+
amount,
54+
}.publish(&e);
4555
}
4656

4757
pub fn set_admin(e: Env, new_admin: Address) {
@@ -53,7 +63,10 @@ impl Token {
5363
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);
5464

5565
admin::write_administrator(&e, &new_admin);
56-
TokenUtils::new(&e).events().set_admin(admin, new_admin);
66+
SetAdmin {
67+
admin: admin.clone(),
68+
new_admin: new_admin.clone(),
69+
}.publish(&e);
5770
}
5871
}
5972

@@ -76,9 +89,12 @@ impl token::Interface for Token {
7689
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);
7790

7891
allowance::write(&e, from.clone(), spender.clone(), amount, expiration_ledger);
79-
TokenUtils::new(&e)
80-
.events()
81-
.approve(from, spender, amount, expiration_ledger);
92+
Approve {
93+
from: from.clone(),
94+
spender: spender.clone(),
95+
amount,
96+
expiration_ledger,
97+
}.publish(&e);
8298
}
8399

84100
fn balance(e: Env, id: Address) -> i128 {
@@ -88,7 +104,7 @@ impl token::Interface for Token {
88104
balance::read(&e, id)
89105
}
90106

91-
fn transfer(e: Env, from: Address, to: Address, amount: i128) {
107+
fn transfer(e: Env, from: Address, to: MuxedAddress, amount: i128) {
92108
from.require_auth();
93109

94110
check_nonnegative_amount(amount);
@@ -97,9 +113,14 @@ impl token::Interface for Token {
97113
.instance()
98114
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);
99115

116+
let to_address = to.address();
100117
balance::spend(&e, from.clone(), amount);
101-
balance::receive(&e, to.clone(), amount);
102-
TokenUtils::new(&e).events().transfer(from, to, amount);
118+
balance::receive(&e, to_address.clone(), amount);
119+
TransferWithAmountOnly {
120+
from: from.clone(),
121+
to: to_address,
122+
amount,
123+
}.publish(&e);
103124
}
104125

105126
fn transfer_from(e: Env, spender: Address, from: Address, to: Address, amount: i128) {
@@ -114,7 +135,11 @@ impl token::Interface for Token {
114135
allowance::spend(&e, from.clone(), spender, amount);
115136
balance::spend(&e, from.clone(), amount);
116137
balance::receive(&e, to.clone(), amount);
117-
TokenUtils::new(&e).events().transfer(from, to, amount);
138+
TransferWithAmountOnly {
139+
from: from.clone(),
140+
to: to.clone(),
141+
amount,
142+
}.publish(&e);
118143
}
119144

120145
fn burn(e: Env, from: Address, amount: i128) {
@@ -127,7 +152,10 @@ impl token::Interface for Token {
127152
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);
128153

129154
balance::spend(&e, from.clone(), amount);
130-
TokenUtils::new(&e).events().burn(from, amount);
155+
Burn {
156+
from: from.clone(),
157+
amount,
158+
}.publish(&e);
131159
}
132160

133161
fn burn_from(e: Env, spender: Address, from: Address, amount: i128) {
@@ -141,7 +169,10 @@ impl token::Interface for Token {
141169

142170
allowance::spend(&e, from.clone(), spender, amount);
143171
balance::spend(&e, from.clone(), amount);
144-
TokenUtils::new(&e).events().burn(from, amount);
172+
Burn {
173+
from: from.clone(),
174+
amount,
175+
}.publish(&e);
145176
}
146177

147178
fn decimals(e: Env) -> u32 {

0 commit comments

Comments
 (0)