Skip to content

Commit

Permalink
fix: set opt-level = 3 for optimizing gas consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
fusede committed Jan 31, 2025
1 parent b621bd1 commit 443c33b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ missing_panics_doc = { level = "allow", priority = -1 }

[profile.release]
codegen-units = 1
opt-level = "z"
opt-level = 3
lto = true
debug = false
strip = "symbols"
Expand Down
2 changes: 1 addition & 1 deletion core/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct AccountEvent<'a, T> {
pub event: T,
}

impl<'a, T> AccountEvent<'a, T> {
impl<T> AccountEvent<'_, T> {
pub fn into_owned(self) -> AccountEvent<'static, T> {
AccountEvent {
account_id: Cow::Owned(self.account_id.into_owned()),
Expand Down
2 changes: 1 addition & 1 deletion core/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ where
}
}

impl<'a, T> From<TokenAmounts<T>> for Cow<'a, TokenAmounts<T>>
impl<T> From<TokenAmounts<T>> for Cow<'_, TokenAmounts<T>>
where
T: Clone,
{
Expand Down
51 changes: 50 additions & 1 deletion tests/src/tests/defuse/intents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use defuse::{
},
intents::SimulationOutput,
};
use near_sdk::AccountId;
use near_sdk::{AccountId, AccountIdRef};
use rand::{thread_rng, Rng};
use serde_json::json;

Expand Down Expand Up @@ -182,3 +182,52 @@ async fn test_simulate_is_view_method() {
0
);
}

#[tokio::test]
async fn test_webauthn() {
let env = Env::new().await;

const SIGNER_ID: &AccountIdRef =
AccountIdRef::new_or_panic("0x3602b546589a8fcafdce7fad64a46f91db0e4d50");

let ft1 = TokenId::Nep141(env.ft1.clone());

// deposit
env.defuse_ft_mint(&env.ft1, 2000, &SIGNER_ID.to_owned())
.await
.unwrap();

env.defuse
.execute_intents([serde_json::from_str(r#"{
"standard": "webauthn",
"payload": "{\"signer_id\":\"0x3602b546589a8fcafdce7fad64a46f91db0e4d50\",\"verifying_contract\":\"defuse.test.near\",\"deadline\":\"2050-03-30T00:00:00Z\",\"nonce\":\"A3nsY1GMVjzyXL3mUzOOP3KT+5a0Ruy+QDNWPhchnxM=\",\"intents\":[{\"intent\":\"transfer\",\"receiver_id\":\"user1.test.near\",\"tokens\":{\"nep141:ft1.poa-factory.test.near\":\"1000\"}}]}",
"public_key": "p256:2V8Np9vGqLiwVZ8qmMmpkxU7CTRqje4WtwFeLimSwuuyF1rddQK5fELiMgxUnYbVjbZHCNnGc6fAe4JeDcVxgj3Q",
"signature": "p256:2wpTbs61923xQU9L4mqBGSdHSdv5mqMn3zRA2tFmDirmPaBPDe5WVtMeGMHt5P4rMN9vC75oZ9hvTCFRrQncpJDn",
"client_data_json": "{\"type\":\"webauthn.get\",\"challenge\":\"DjS-6fxaPS3avW-4ls8dDYAynCmsAXWCF86cJBTkHbs\",\"origin\":\"https://defuse-widget-git-feat-passkeys-defuse-94bbc1b2.vercel.app\"}",
"authenticator_data": "933cQogpBzE3RSAYSAkfWoNEcBd3X84PxE8iRrRVxMgdAAAAAA=="
}"#).unwrap(), serde_json::from_str(r#"{
"standard": "webauthn",
"payload": "{\"signer_id\":\"0x3602b546589a8fcafdce7fad64a46f91db0e4d50\",\"verifying_contract\":\"defuse.test.near\",\"deadline\":\"2050-03-30T00:00:00Z\",\"nonce\":\"B3nsY1GMVjzyXL3mUzOOP3KT+5a0Ruy+QDNWPhchnxM=\",\"intents\":[{\"intent\":\"transfer\",\"receiver_id\":\"user1.test.near\",\"tokens\":{\"nep141:ft1.poa-factory.test.near\":\"1000\"}}]}",
"public_key": "p256:2V8Np9vGqLiwVZ8qmMmpkxU7CTRqje4WtwFeLimSwuuyF1rddQK5fELiMgxUnYbVjbZHCNnGc6fAe4JeDcVxgj3Q",
"signature": "p256:5Zq1w2ntVi5EowuKPnaSyuM2XB3JsQZub5CXB1fHsP6Mf4uvezu5YYmo8tCAjkMguxzhQq4DrpeD5QTjCVGpaRMs",
"client_data_json": "{\"type\":\"webauthn.get\",\"challenge\":\"6ULo-LNIjd8Gh1mdxzUdHzv2AuGDWMchOORdDnaLXHc\",\"origin\":\"https://defuse-widget-git-feat-passkeys-defuse-94bbc1b2.vercel.app\"}",
"authenticator_data": "933cQogpBzE3RSAYSAkfWoNEcBd3X84PxE8iRrRVxMgdAAAAAA=="
}"#).unwrap()])
.await
.unwrap();

assert_eq!(
env.defuse
.mt_balance_of(env.user1.id(), &ft1.to_string())
.await
.unwrap(),
2000
);
assert_eq!(
env.defuse
.mt_balance_of(&SIGNER_ID.to_owned(), &ft1.to_string())
.await
.unwrap(),
0
);
}
2 changes: 1 addition & 1 deletion tests/src/utils/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait AccountExt {
impl AccountExt for Account {
async fn deploy_contract(&self, account_id: &str, wasm: &[u8]) -> anyhow::Result<Contract> {
self.create_subaccount(account_id)
.initial_balance(NearToken::from_near(10))
.initial_balance(NearToken::from_near(15))
.transact()
.await?
.into_result()?
Expand Down

0 comments on commit 443c33b

Please sign in to comment.