Skip to content

Commit

Permalink
release: 1.2.1 (#68)
Browse files Browse the repository at this point in the history
- test: automatically generated integration tests implementations (#62)
- test: contract call as future in integration tests (#64)
- chore: update integration utils (#65)
- fix: use all available gas for xcc (#66)
- build: bump version (#67)
  • Loading branch information
vasyafromrussia authored Feb 27, 2024
2 parents 9bcdfff + 816c6ed commit 9f0f88b
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 324 deletions.
22 changes: 4 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
members = [
"sweat",
"sweat",
"sweat-integration",
"integration-tests",
"exploit-stub"
]
Expand All @@ -20,8 +19,7 @@ near-workspaces = "0.10.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 = "c30efebede6a3e40111c3be95e89564fe2698db1" }
integration-utils = { git = "https://github.com/sweatco/integration-utils.git", rev = "c30efebede6a3e40111c3be95e89564fe2698db1" }
integration-trait = { git = "https://github.com/sweatco/integration-utils.git", rev = "e54dc392ef42837123dd2c0ad19b6d6b815192d7" }
integration-utils = { git = "https://github.com/sweatco/integration-utils.git", rev = "e54dc392ef42837123dd2c0ad19b6d6b815192d7" }

sweat-model = { path = "model" }
sweat-integration = { path = "sweat-integration" }
1 change: 0 additions & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ pkg-config = "0.3.1"
async-trait = "0.1.73"

sweat-model = { workspace = true, features = ["integration-test"] }
sweat-integration = { workspace = true }
integration-utils = { workspace = true }
10 changes: 5 additions & 5 deletions integration-tests/src/callback_attack.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(test)]

use integration_utils::{integration_contract::IntegrationContract, misc::ToNear};
use integration_utils::misc::ToNear;
use near_sdk::{json_types::U128, serde_json::json};
use sweat_model::FungibleTokenCoreIntegration;

Expand All @@ -16,7 +16,7 @@ async fn test_call_on_record_in_callback() -> anyhow::Result<()> {

let alice = context.alice().await?;

let alice_balance_before_attack = context.ft_contract().ft_balance_of(alice.to_near()).call().await?;
let alice_balance_before_attack = context.ft_contract().ft_balance_of(alice.to_near()).await?;
let ft_contract_id = context.ft_contract().account();

let target_amount = U128(1_000_000);
Expand All @@ -33,7 +33,7 @@ async fn test_call_on_record_in_callback() -> anyhow::Result<()> {

assert!(result.has_panic("Method on_record is private"));

let alice_balance_after_attack = context.ft_contract().ft_balance_of(alice.to_near()).call().await?;
let alice_balance_after_attack = context.ft_contract().ft_balance_of(alice.to_near()).await?;
assert_eq!(alice_balance_before_attack, alice_balance_after_attack);

Ok(())
Expand All @@ -48,9 +48,9 @@ async fn test_call_on_record_directly() -> anyhow::Result<()> {
let intruder_id = alice.to_near();
let result = context
.ft_contract()
.contract()
.contract
.as_account()
.call(context.ft_contract().contract().id(), "on_record")
.call(context.ft_contract().contract.id(), "on_record")
.args_json(json!({
"receiver_id": intruder_id,
"amount": "1000000",
Expand Down
8 changes: 2 additions & 6 deletions integration-tests/src/defer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ async fn test_defer() -> anyhow::Result<()> {
let holder_balance = context
.ft_contract()
.ft_balance_of(claim_contract_account.clone())
.call()
.await?;

assert_eq!(holder_balance.0, 0);

let (total_fee, total_for_user) = context
.ft_contract()
.calculate_payout_with_fee_for_batch(BATCH_SIZE, CLAIM_AMOUNT)
.call()
.await?;

let batch: Vec<_> = (0..BATCH_SIZE).map(|_| (alice.to_near(), CLAIM_AMOUNT)).collect();
Expand All @@ -36,19 +34,17 @@ async fn test_defer() -> anyhow::Result<()> {
.ft_contract()
.defer_batch(batch, claim_contract_account.clone())
.with_user(&oracle)
.call()
.await?;

let alice_balance = context.ft_contract().ft_balance_of(alice.to_near()).call().await?;
let alice_balance = context.ft_contract().ft_balance_of(alice.to_near()).await?;
assert_eq!(0, alice_balance.0);

let claim_contract_balance = context
.ft_contract()
.ft_balance_of(claim_contract_account.clone())
.call()
.await?;

let oracle_balance = context.ft_contract().ft_balance_of(oracle.to_near()).call().await?;
let oracle_balance = context.ft_contract().ft_balance_of(oracle.to_near()).await?;

assert_eq!(oracle_balance, total_fee);
assert_eq!(claim_contract_balance, total_for_user);
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/src/formula.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn test_formula() -> Result<()> {

let oracle = context.oracle().await?;

let steps = context.ft_contract().get_steps_since_tge().call().await?;
let steps = context.ft_contract().get_steps_since_tge().await?;

assert_eq!(0, steps.0);

Expand Down Expand Up @@ -43,7 +43,6 @@ async fn test_formula() -> Result<()> {
.ft_contract()
.formula(U64(tge), steps)
.with_user(&oracle)
.call()
.await?
.0;

Expand Down
7 changes: 3 additions & 4 deletions integration-tests/src/interface/common.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use integration_utils::integration_contract::IntegrationContract;
use near_sdk::AccountId;
use sweat_integration::SweatFt;
use sweat_model::SweatContract;

pub(crate) trait ContractAccount {
fn account(&self) -> AccountId;
}

impl ContractAccount for SweatFt<'_> {
impl ContractAccount for SweatContract<'_> {
fn account(&self) -> AccountId {
AccountId::new_unchecked(self.contract().as_account().id().to_string())
AccountId::new_unchecked(self.contract.as_account().id().to_string())
}
}
6 changes: 2 additions & 4 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ async fn happy_flow() -> anyhow::Result<()> {

assert_eq!(
99999995378125008,
context.ft_contract().formula(100_000.into(), 100).call().await?.0
context.ft_contract().formula(100_000.into(), 100).await?.0
);

context
.ft_contract()
.tge_mint(&alice.to_near(), 100_000_000.into())
.call()
.await?;

assert_eq!(
100_000_000,
context.ft_contract().ft_balance_of(alice.to_near()).call().await?.0
context.ft_contract().ft_balance_of(alice.to_near()).await?.0
);

context
Expand All @@ -45,7 +44,6 @@ async fn happy_flow() -> anyhow::Result<()> {
context.claim_contract().as_account().to_near(),
)
.with_user(&oracle)
.call()
.await?;

Ok(())
Expand Down
4 changes: 3 additions & 1 deletion integration-tests/src/measure/record_batch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![cfg(test)]

use std::future::IntoFuture;

use anyhow::Result;
use integration_utils::measure::outcome_storage::OutcomeStorage;
use near_workspaces::types::Gas;
Expand Down Expand Up @@ -28,7 +30,7 @@ async fn measure_record_batch() -> Result<Gas> {
.ft_contract()
.record_batch(Default::default())
.with_user(&oracle)
.call(),
.into_future(),
)
.await?;

Expand Down
15 changes: 5 additions & 10 deletions integration-tests/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,27 @@ async fn test_mint() -> anyhow::Result<()> {
let user = context.alice().await?;
let oracle = context.oracle().await?;

let result = context.ft_contract().get_steps_since_tge().call().await?;
let result = context.ft_contract().get_steps_since_tge().await?;
assert_eq!(result, U64(0));

let result = context
.ft_contract()
.formula(U64(0), TARGET_STEPS_SINCE_TGE)
.call()
.await?;
let result = context.ft_contract().formula(U64(0), TARGET_STEPS_SINCE_TGE).await?;
assert_eq!(result, U128(TARGET_BALANCE));

context
.ft_contract()
.record_batch(vec![(user.to_near(), 10_000u32)])
.with_user(&oracle)
.call()
.await?;

let target_payout = Payout::from(TARGET_BALANCE);

let result = context.ft_contract().ft_balance_of(oracle.to_near()).call().await?;
let result = context.ft_contract().ft_balance_of(oracle.to_near()).await?;
assert_eq!(result, U128(target_payout.fee));

let result = context.ft_contract().ft_balance_of(user.to_near()).call().await?;
let result = context.ft_contract().ft_balance_of(user.to_near()).await?;
assert_eq!(result, U128(target_payout.amount_for_user));

let result = context.ft_contract().get_steps_since_tge().call().await?;
let result = context.ft_contract().get_steps_since_tge().await?;
assert_eq!(result, U64(TARGET_STEPS_SINCE_TGE as u64));

Ok(())
Expand Down
29 changes: 12 additions & 17 deletions integration-tests/src/prepare.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use anyhow::Result;
use async_trait::async_trait;
use integration_utils::{integration_contract::IntegrationContract, misc::ToNear};
use integration_utils::misc::ToNear;
use near_sdk::serde_json::json;
use near_workspaces::{Account, Contract};
use sweat_integration::{SweatFt, FT_CONTRACT};
use sweat_model::{StorageManagementIntegration, SweatApiIntegration};
use sweat_model::{StorageManagementIntegration, SweatApiIntegration, SweatContract};

const CLAIM_CONTRACT: &str = "sweat_claim";
const HOLDING_STUB_CONTRACT: &str = "exploit_stub";
const FT_CONTRACT: &str = "sweat";

pub type Context = integration_utils::context::Context<near_workspaces::network::Sandbox>;

Expand All @@ -18,7 +18,7 @@ pub trait IntegrationContext {
async fn bob(&mut self) -> Result<Account>;
async fn long_account_name(&mut self) -> Result<Account>;

fn ft_contract(&self) -> SweatFt;
fn ft_contract(&self) -> SweatContract;
fn claim_contract(&self) -> &Contract;
fn stub_contract(&self) -> &Contract;
}
Expand All @@ -41,8 +41,10 @@ impl IntegrationContext for Context {
self.account("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").await
}

fn ft_contract(&self) -> SweatFt {
SweatFt::with_contract(&self.contracts[FT_CONTRACT])
fn ft_contract(&self) -> SweatContract {
SweatContract {
contract: &self.contracts[FT_CONTRACT],
}
}

fn claim_contract(&self) -> &Contract {
Expand All @@ -57,39 +59,33 @@ impl IntegrationContext for Context {
pub async fn prepare_contract() -> Result<Context> {
let mut context = Context::new(
&[FT_CONTRACT, CLAIM_CONTRACT, HOLDING_STUB_CONTRACT],
true,
"build-integration".into(),
)
.await?;
let oracle = context.oracle().await?;
let alice = context.alice().await?;
let long = context.long_account_name().await?;
let token_account_id = context.ft_contract().contract().as_account().to_near();
let token_account_id = context.ft_contract().contract.as_account().to_near();

context
.ft_contract()
.new(".u.sweat.testnet".to_string().into())
.call()
.await?;
context.ft_contract().new(".u.sweat.testnet".to_string().into()).await?;

context
.ft_contract()
.storage_deposit(oracle.to_near().into(), None)
.call()
.await?;

context
.ft_contract()
.storage_deposit(alice.to_near().into(), None)
.call()
.await?;

context
.ft_contract()
.storage_deposit(long.to_near().into(), None)
.call()
.await?;

context.ft_contract().add_oracle(&oracle.to_near()).call().await?;
context.ft_contract().add_oracle(&oracle.to_near()).await?;

let claim_contract_result = context
.claim_contract()
Expand Down Expand Up @@ -124,7 +120,6 @@ pub async fn prepare_contract() -> Result<Context> {
context
.ft_contract()
.storage_deposit(context.claim_contract().as_account().to_near().into(), None)
.call()
.await?;

Ok(context)
Expand Down
Loading

0 comments on commit 9f0f88b

Please sign in to comment.