Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 01f924d

Browse files
committed
feedback: rework rent check and test tx dedupe
1 parent cd22c3e commit 01f924d

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

token/client/src/token.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -3876,19 +3876,23 @@ where
38763876
&self,
38773877
) -> TokenResult<u64> {
38783878
let account = self.get_account(self.pubkey).await?;
3879+
let account_data_len = account.data.len();
38793880
let account_lamports = account.lamports;
3880-
let new_account_len = account
3881-
.data
3882-
.len()
3883-
.saturating_add(size_of::<ExtensionType>())
3884-
.saturating_add(size_of::<Length>())
3885-
.saturating_add(size_of::<V>());
3886-
let new_rent_exempt_minimum = self
3887-
.client
3888-
.get_minimum_balance_for_rent_exemption(new_account_len)
3889-
.await
3890-
.map_err(TokenError::Client)?;
3891-
Ok(new_rent_exempt_minimum.saturating_sub(account_lamports))
3881+
let mint_state = self.unpack_mint_info(account)?;
3882+
if mint_state.get_extension::<V>().is_ok() {
3883+
Ok(0)
3884+
} else {
3885+
let new_account_len = account_data_len
3886+
.saturating_add(size_of::<ExtensionType>())
3887+
.saturating_add(size_of::<Length>())
3888+
.saturating_add(size_of::<V>());
3889+
let new_rent_exempt_minimum = self
3890+
.client
3891+
.get_minimum_balance_for_rent_exemption(new_account_len)
3892+
.await
3893+
.map_err(TokenError::Client)?;
3894+
Ok(new_rent_exempt_minimum.saturating_sub(account_lamports))
3895+
}
38923896
}
38933897

38943898
/// Initialize token-group on a mint

token/program-2022-test/tests/program_test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl TestContext {
146146
let token_unchecked = Token::new_native(Arc::clone(&client), &id(), Arc::new(payer));
147147
self.token_context = Some(TokenContext {
148148
decimals: native_mint::DECIMALS,
149-
mint_authority: Keypair::new(), /*bogus*/
149+
mint_authority: Keypair::new(), /* bogus */
150150
token,
151151
token_unchecked,
152152
alice: Keypair::new(),

token/program-2022-test/tests/token_group_initialize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async fn success_initialize() {
131131
&payer_pubkey,
132132
&token_context.mint_authority.pubkey(),
133133
&update_authority,
134-
max_size,
134+
12, // Change so we get a different transaction
135135
&[&token_context.mint_authority],
136136
)
137137
.await
@@ -140,7 +140,7 @@ async fn success_initialize() {
140140
error,
141141
TokenClientError::Client(Box::new(TransportError::TransactionError(
142142
TransactionError::InstructionError(
143-
1,
143+
0, // No additional rent
144144
InstructionError::Custom(TokenError::ExtensionAlreadyInitialized as u32)
145145
)
146146
)))

0 commit comments

Comments
 (0)