diff --git a/Cargo.lock b/Cargo.lock index 3f7d9f9..f41eea1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1710,7 +1710,7 @@ dependencies = [ [[package]] name = "integration-trait" version = "0.1.0" -source = "git+https://github.com/sweatco/integration-utils.git?rev=b3e5b747b930ebc04601146deda13f12615d5e01#b3e5b747b930ebc04601146deda13f12615d5e01" +source = "git+https://github.com/sweatco/integration-utils.git?rev=2c3512ffba1540271a6b09ed266961173fce15c8#2c3512ffba1540271a6b09ed266961173fce15c8" dependencies = [ "proc-macro2", "quote", @@ -1720,7 +1720,7 @@ dependencies = [ [[package]] name = "integration-utils" version = "0.1.0" -source = "git+https://github.com/sweatco/integration-utils.git?rev=b3e5b747b930ebc04601146deda13f12615d5e01#b3e5b747b930ebc04601146deda13f12615d5e01" +source = "git+https://github.com/sweatco/integration-utils.git?rev=2c3512ffba1540271a6b09ed266961173fce15c8#2c3512ffba1540271a6b09ed266961173fce15c8" dependencies = [ "anyhow", "async-trait", @@ -2359,7 +2359,7 @@ dependencies = [ "near-primitives 0.14.0", "near-primitives-core 0.14.0", "near-sdk-macros 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "near-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "near-sys 0.2.1", "near-vm-logic", "once_cell", "schemars", @@ -2381,7 +2381,7 @@ dependencies = [ "near-primitives 0.14.0", "near-primitives-core 0.14.0", "near-sdk-macros 4.1.1 (git+https://github.com/sweatco/near-sdk-rs?rev=8c48b26cc48d969c1e5f3162141fe9c824fccecd)", - "near-sys 0.2.0 (git+https://github.com/sweatco/near-sdk-rs?rev=8c48b26cc48d969c1e5f3162141fe9c824fccecd)", + "near-sys 0.2.0", "near-vm-logic", "once_cell", "schemars", @@ -2422,13 +2422,13 @@ checksum = "6540152fba5e96fe5d575b79e8cd244cf2add747bb01362426bdc069bc3a23bc" [[package]] name = "near-sys" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e307313276eaeced2ca95740b5639e1f3125b7c97f0a1151809d105f1aa8c6d3" +source = "git+https://github.com/sweatco/near-sdk-rs?rev=8c48b26cc48d969c1e5f3162141fe9c824fccecd#8c48b26cc48d969c1e5f3162141fe9c824fccecd" [[package]] name = "near-sys" -version = "0.2.0" -source = "git+https://github.com/sweatco/near-sdk-rs?rev=8c48b26cc48d969c1e5f3162141fe9c824fccecd#8c48b26cc48d969c1e5f3162141fe9c824fccecd" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "397688591acf8d3ebf2c2485ba32d4b24fc10aad5334e3ad8ec0b7179bfdf06b" [[package]] name = "near-token" diff --git a/Cargo.toml b/Cargo.toml index 0869ae5..460c1fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,12 +14,13 @@ tokio = "1.28.0" anyhow = "1.0.75" async-trait = "0.1.74" +near-units = "0.2.0" near-workspaces = "0.9.0" near-sdk = { git = "https://github.com/sweatco/near-sdk-rs", rev = "8c48b26cc48d969c1e5f3162141fe9c824fccecd" } near-contract-standards = { git = "https://github.com/sweatco/near-sdk-rs", rev = "8c48b26cc48d969c1e5f3162141fe9c824fccecd" } -integration-trait = { git = "https://github.com/sweatco/integration-utils.git", rev = "b3e5b747b930ebc04601146deda13f12615d5e01" } -integration-utils = { git = "https://github.com/sweatco/integration-utils.git", rev = "b3e5b747b930ebc04601146deda13f12615d5e01" } +integration-trait = { git = "https://github.com/sweatco/integration-utils.git", rev = "2c3512ffba1540271a6b09ed266961173fce15c8" } +integration-utils = { git = "https://github.com/sweatco/integration-utils.git", rev = "2c3512ffba1540271a6b09ed266961173fce15c8" } sweat-model = { path = "model" } sweat-integration = { path = "sweat-integration" } diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 8bc8e8d..ed1d0e3 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -14,7 +14,7 @@ near-contract-standards = { workspace = true } anyhow = { workspace = true } tokio = { workspace = true } -near-units = "0.2.0" +near-units = { workspace = true } borsh = "0.10.3" maplit = "1.0" tracing = "0.1.37" diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 52819cc..c6d3dc1 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -10,6 +10,7 @@ mod common; mod defer; mod formula; mod interface; +mod measure; mod mint; mod prepare; mod transfer; diff --git a/integration-tests/src/measure/mod.rs b/integration-tests/src/measure/mod.rs new file mode 100644 index 0000000..d5a8194 --- /dev/null +++ b/integration-tests/src/measure/mod.rs @@ -0,0 +1 @@ +mod record_batch; diff --git a/integration-tests/src/measure/record_batch.rs b/integration-tests/src/measure/record_batch.rs new file mode 100644 index 0000000..dbf74b2 --- /dev/null +++ b/integration-tests/src/measure/record_batch.rs @@ -0,0 +1,36 @@ +#![cfg(test)] + +use anyhow::Result; +use integration_utils::measure::outcome_storage::OutcomeStorage; +use near_workspaces::types::Gas; +use sweat_model::SweatApiIntegration; + +use crate::{prepare::IntegrationContext, prepare_contract}; + +#[ignore] +#[tokio::test] +async fn single_record_batch() -> anyhow::Result<()> { + let gas = measure_record_batch().await?; + + dbg!(&gas); + + Ok(()) +} + +async fn measure_record_batch() -> Result { + let mut context = prepare_contract().await?; + + let oracle = context.oracle().await?; + + let (gas, _) = OutcomeStorage::measure_total( + &oracle, + context + .ft_contract() + .record_batch(Default::default()) + .with_user(&oracle) + .call(), + ) + .await?; + + Ok(gas) +} diff --git a/res/sweat.wasm b/res/sweat.wasm index 131d77d..4ea559f 100755 Binary files a/res/sweat.wasm and b/res/sweat.wasm differ diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 71326c3..6d833ff 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.74" +channel = "1.75" diff --git a/sweat-integration/Cargo.toml b/sweat-integration/Cargo.toml index 96af39e..56b4a12 100644 --- a/sweat-integration/Cargo.toml +++ b/sweat-integration/Cargo.toml @@ -10,7 +10,7 @@ integration-utils = { workspace = true } sweat-model = { workspace = true, features = ["integration-test"] } -near-units = "0.2.0" +near-units = { workspace = true } near-sdk = { workspace = true } near-contract-standards = { workspace = true } -near-workspaces = "0.9.0" +near-workspaces = { workspace = true } diff --git a/sweat/src/defer.rs b/sweat/src/defer.rs index 731b446..d2f60fa 100644 --- a/sweat/src/defer.rs +++ b/sweat/src/defer.rs @@ -3,6 +3,8 @@ use sweat_model::SweatDefer; use crate::*; +const ONE_GGAS: u64 = Gas::ONE_TERA.0 / 1000; + #[near_bindgen] impl SweatDefer for Contract { fn defer_batch(&mut self, steps_batch: Vec<(AccountId, u32)>, holding_account_id: AccountId) -> PromiseOrValue<()> { @@ -11,6 +13,8 @@ impl SweatDefer for Contract { "Unauthorized access! Only oracle can call that!" ); + let batch_len = steps_batch.len() as u64; + let mut accounts_tokens: Vec<(AccountId, U128)> = Vec::new(); let mut total_effective: U128 = U128(0); let mut total_fee: U128 = U128(0); @@ -28,16 +32,19 @@ impl SweatDefer for Contract { "amounts": accounts_tokens, }); + // These values calculated in `measure_record_batch_for_hold_test` in claim contract. + let record_batch_for_hold_gas = Gas::ONE_TERA * 8 + Gas(batch_len * ONE_GGAS * 320); + Promise::new(holding_account_id.clone()) .function_call( "record_batch_for_hold".to_string(), hold_arguments.to_string().into_bytes(), 0, - Gas(20 * 1_000_000_000_000), + record_batch_for_hold_gas, ) .then( ext_ft_transfer_callback::ext(env::current_account_id()) - .with_static_gas(Gas(5 * 1_000_000_000_000)) + .with_static_gas(Gas::ONE_TERA * 5) .on_record( holding_account_id, total_effective,