Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
K1-R1 authored and Salka1988 committed Sep 6, 2024
1 parent b2805f9 commit 1a34ae5
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 174 deletions.
31 changes: 16 additions & 15 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[package]
name = "sway-standard-implementations-tests"
version = "0.0.0"
authors = ["Fuel Labs <[email protected]>"]
edition = "2021"
license = "Apache-2.0"

[dependencies]
fuels = { version = "0.66.3" }
tokio = { version = "1.39.3", features = ["rt", "macros"] }

[[test]]
harness = true
name = "sway-standard-implementations-tests"
path = "src/harness.rs"
[package]
name = "sway-standard-implementations-tests"
version = "0.0.0"
authors = ["Fuel Labs <[email protected]>"]
edition = "2021"
license = "Apache-2.0"

[dependencies]
fuels = { version = "0.66.3" }

tokio = { version = "1.39.3", features = ["rt", "macros"] }

[[test]]
harness = true
name = "sway-standard-implementations-tests"
path = "src/harness.rs"
2 changes: 1 addition & 1 deletion tests/fuel-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "nightly-2024-09-05"
channel = "stable"

[components]
forc = "0.63.3"
Expand Down
36 changes: 23 additions & 13 deletions tests/src/src14/owned_proxy/tests/functions/initialize_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,51 @@ use crate::src14::owned_proxy::tests::utils::{
State,
};

use fuels::types::errors::Result;

mod success {

use super::*;

#[tokio::test]
async fn only_owner_may_call() {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await;
async fn only_owner_may_call() -> Result<()> {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await?;

assert_eq!(proxy_target(&owner1.proxy_contract).await.value, None);
assert_eq!(proxy_target(&owner1.proxy_contract).await?.value, None);
assert_eq!(
proxy_owner(&owner1.proxy_contract).await.value,
proxy_owner(&owner1.proxy_contract).await?.value,
State::Uninitialized
);

initialize_proxy(&owner1.proxy_contract).await;
initialize_proxy(&owner1.proxy_contract).await?;

assert_ne!(proxy_target(&owner1.proxy_contract).await.value, None);
assert_ne!(proxy_target(&owner1.proxy_contract).await?.value, None);
assert_ne!(
proxy_owner(&owner1.proxy_contract).await.value,
proxy_owner(&owner1.proxy_contract).await?.value,
State::Uninitialized
);

Ok(())
}
}

mod reverts {

use super::*;
use fuels::prelude::Error;
use fuels::types::errors::transaction::Reason;

#[tokio::test]
#[should_panic(expected = "CannotReinitialized")]
async fn when_not_owner() {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await;
async fn when_not_owner() -> Result<()> {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await?;

initialize_proxy(&owner1.proxy_contract).await?;

initialize_proxy(&owner1.proxy_contract).await;
let err = initialize_proxy(&owner1.proxy_contract).await;

initialize_proxy(&owner1.proxy_contract).await;
assert!(matches!(
err.unwrap_err(),
Error::Transaction(Reason::Reverted { reason, .. } ) if reason == "CannotReinitialized"
));
Ok(())
}
}
26 changes: 15 additions & 11 deletions tests/src/src14/owned_proxy/tests/functions/proxy_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,39 @@ mod success {
test_helpers::setup,
State,
};

use fuels::types::errors::Result;
#[tokio::test]
async fn returns_initialized_owner() {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await;
async fn returns_initialized_owner() -> Result<()> {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await?;

assert_eq!(
proxy_owner(&owner1.proxy_contract).await.value,
proxy_owner(&owner1.proxy_contract).await?.value,
State::Uninitialized
);

initialize_proxy(&owner1.proxy_contract).await;
initialize_proxy(&owner1.proxy_contract).await?;

assert_eq!(
proxy_owner(&owner1.proxy_contract).await.value,
proxy_owner(&owner1.proxy_contract).await?.value,
State::Initialized(owner1.wallet.address().into())
);

Ok(())
}

#[tokio::test]
async fn returns_owner_on_state_change() {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await;
async fn returns_owner_on_state_change() -> Result<()> {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await?;

initialize_proxy(&owner1.proxy_contract).await;
initialize_proxy(&owner1.proxy_contract).await?;

set_proxy_owner(&owner1.proxy_contract, State::Revoked).await;
set_proxy_owner(&owner1.proxy_contract, State::Revoked).await?;

assert_eq!(
proxy_owner(&owner1.proxy_contract).await.value,
proxy_owner(&owner1.proxy_contract).await?.value,
State::Revoked
);

Ok(())
}
}
13 changes: 7 additions & 6 deletions tests/src/src14/owned_proxy/tests/functions/proxy_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ mod success {
proxy_abi_calls::{initialize_proxy, proxy_target},
test_helpers::setup,
};

use fuels::types::errors::Result;
#[tokio::test]
async fn returns_initialized_target() {
let (_deployer, owner1, _owner2, initial_target_id) = setup().await;
async fn returns_initialized_target() -> Result<()> {
let (_deployer, owner1, _owner2, initial_target_id) = setup().await?;

assert_eq!(proxy_target(&owner1.proxy_contract).await.value, None);
assert_eq!(proxy_target(&owner1.proxy_contract).await?.value, None);

initialize_proxy(&owner1.proxy_contract).await;
initialize_proxy(&owner1.proxy_contract).await?;

assert_eq!(
proxy_target(&owner1.proxy_contract).await.value,
proxy_target(&owner1.proxy_contract).await?.value,
Some(initial_target_id)
);
Ok(())
}
}
84 changes: 57 additions & 27 deletions tests/src/src14/owned_proxy/tests/functions/set_proxy_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,116 @@ use crate::src14::owned_proxy::tests::utils::{
State,
};

use fuels::types::errors::Result;

mod success {

use super::*;

#[tokio::test]
async fn sets_a_new_owner() {
let (_deployer, owner1, owner2, _initial_target_id) = setup().await;
async fn sets_a_new_owner() -> Result<()> {
let (_deployer, owner1, owner2, _initial_target_id) = setup().await?;

initialize_proxy(&owner1.proxy_contract).await;
initialize_proxy(&owner1.proxy_contract).await?;

assert_eq!(
proxy_owner(&owner1.proxy_contract).await.value,
proxy_owner(&owner1.proxy_contract).await?.value,
State::Initialized(owner1.wallet.address().into())
);

set_proxy_owner(
&owner1.proxy_contract,
State::Initialized(owner2.wallet.address().into()),
)
.await;
.await?;

assert_eq!(
proxy_owner(&owner1.proxy_contract).await.value,
proxy_owner(&owner1.proxy_contract).await?.value,
State::Initialized(owner2.wallet.address().into())
);

Ok(())
}

#[tokio::test]
async fn revokes_ownership() {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await;
async fn revokes_ownership() -> Result<()> {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await?;

initialize_proxy(&owner1.proxy_contract).await;
initialize_proxy(&owner1.proxy_contract).await?;

assert_eq!(
proxy_owner(&owner1.proxy_contract).await.value,
proxy_owner(&owner1.proxy_contract).await?.value,
State::Initialized(owner1.wallet.address().into())
);

set_proxy_owner(&owner1.proxy_contract, State::Revoked).await;
set_proxy_owner(&owner1.proxy_contract, State::Revoked).await?;

assert_eq!(
proxy_owner(&owner1.proxy_contract).await.value,
proxy_owner(&owner1.proxy_contract).await?.value,
State::Revoked
);
Ok(())
}
}

mod reverts {

use super::*;
use fuels::prelude::Error;
use fuels::types::errors::transaction::Reason;

#[tokio::test]
#[should_panic(expected = "NotOwner")]
async fn when_called_by_non_owner() {
let (_deployer, _owner1, owner2, _initial_target_id) = setup().await;
async fn when_called_by_non_owner() -> Result<()> {
let (_deployer, _owner1, owner2, _initial_target_id) = setup().await?;

initialize_proxy(&owner2.proxy_contract).await;
initialize_proxy(&owner2.proxy_contract).await?;

set_proxy_owner(
let err = set_proxy_owner(
&owner2.proxy_contract,
State::Initialized(owner2.wallet.address().into()),
)
.await;

assert!(matches!(
err.unwrap_err(),
Error::Transaction(
Reason::Reverted { reason, .. }
) if reason == "NotOwner"
));

Ok(())
}

#[tokio::test]
#[should_panic(expected = "CannotUninitialize")]
async fn when_setting_the_new_state_to_uninitialized() {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await;
async fn when_setting_the_new_state_to_uninitialized() -> Result<()> {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await?;

initialize_proxy(&owner1.proxy_contract).await?;

let err = set_proxy_owner(&owner1.proxy_contract, State::Uninitialized).await;

initialize_proxy(&owner1.proxy_contract).await;
assert!(matches!(
err.unwrap_err(),
Error::Transaction(
Reason::Reverted { reason, .. }
) if reason == "CannotUninitialize"
));

set_proxy_owner(&owner1.proxy_contract, State::Uninitialized).await;
Ok(())
}

#[tokio::test]
#[should_panic(expected = "NotOwner")]
async fn when_not_initialized() {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await;
async fn when_not_initialized() -> Result<()> {
let (_deployer, owner1, _owner2, _initial_target_id) = setup().await?;

let err = set_proxy_owner(&owner1.proxy_contract, State::Revoked).await;

assert!(matches!(
err.unwrap_err(),
Error::Transaction(
Reason::Reverted { reason, .. }
) if reason == "NotOwner"
));

set_proxy_owner(&owner1.proxy_contract, State::Revoked).await;
Ok(())
}
}
Loading

0 comments on commit 1a34ae5

Please sign in to comment.