Skip to content

Commit

Permalink
Updating contract tests after IR. Also, some cleanup. (#1141)
Browse files Browse the repository at this point in the history
* Updating contract tests after IR. Also, some cleanup.

* fixing std lib dependency

* disabling the broken test again
  • Loading branch information
mohammadfawaz authored Apr 5, 2022
1 parent 264f60b commit 56b3eb9
Show file tree
Hide file tree
Showing 34 changed files with 56 additions and 207 deletions.
24 changes: 5 additions & 19 deletions test/src/e2e_vm_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,10 @@ pub fn run(filter_regex: Option<regex::Regex>) {
// with some known state. Note that if a non-contract is included
// it will be rejected during assertion. Please move it to
// `positive_project_names_no_abi` above.
let positive_project_names_with_abi = vec![
// contracts revert because this test runs them against the VM
// and no selectors will match
(
"should_pass/test_contracts/contract_abi_impl",
ProgramState::Revert(0),
),
(
"should_pass/language/valid_impurity",
ProgramState::Revert(0), // false
),
];
let positive_project_names_with_abi = vec![(
"should_pass/language/valid_impurity",
ProgramState::Revert(0), // false
)];

number_of_tests_run += positive_project_names_with_abi
.iter()
Expand Down Expand Up @@ -397,10 +389,6 @@ pub fn run(filter_regex: Option<regex::Regex>) {
"should_pass/test_contracts/context_testing_contract",
"should_pass/require_contract_deployment/caller_context_test",
),
(
"should_pass/test_contracts/contract_abi_impl",
"should_pass/require_contract_deployment/contract_call",
),
(
"should_pass/test_contracts/balance_test_contract",
"should_pass/require_contract_deployment/bal_opcode",
Expand All @@ -409,12 +397,10 @@ pub fn run(filter_regex: Option<regex::Regex>) {
"should_pass/test_contracts/test_fuel_coin_contract",
"should_pass/require_contract_deployment/token_ops_test",
),
/* Requires IR - TODO:enable when the IR pipeline is enabled by default
* https://github.com/FuelLabs/sway/issues/981
(
"should_pass/test_contracts/storage_access_contract",
"should_pass/require_contract_deployment/storage_access_caller",
),*/
),
];

let total_number_of_tests = positive_project_names_no_abi.len()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "bal_opcode"

[dependencies]
balance_test_abi = { path = "../../test_abis/balance_test_abi" }
std = { path = "../../../../../../../sway-lib-std" }
balance_test_abi = { path = "../../test_abis/balance_test_abi"}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use balance_test_abi::BalanceTest;

fn main() -> bool {
// @todo switch to using ContractId when abi signature changes.
let balance_test_contract_id = 0xa835193dabf3fe80c0cb62e2ecc424f5ac03bc7f5c896ecc4bd2fd06cc434322;
let balance_test_contract_id = 0xb4c0d8c9056c0cde34b66e7e4e3f361d927d26ffdc16c2645dd0e2699bc96cad;

let balance_test_contract = abi(BalanceTest, balance_test_contract_id);
let number = balance_test_contract.get_42 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
script;
use basic_storage_abi::StoreU64;
use std::assert::assert;

fn main() -> u64 {
let addr = abi(StoreU64, 0x3eedeb06664177bd0dea0a1fe0d6e9645c45b8693c902f3a6f67649044f41c9a);
let addr = abi(StoreU64, 0xf4e12fcac2187e1ac5599476c531560cb6f7aa39bd05d20312a4bd237900b4e4);
let key = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
let value = 4242;

addr.store_u64(key, value);

let res = addr.get_u64(key);
assert(res == value);

res
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use increment_abi::Incrementor;
use std::assert::assert;

fn main() {
let abi = abi(Incrementor, 0x4c30f62e9947cff714c802afc0c900de272dbeec57ae12ed96aacbfd32c3e3a8);
let abi = abi(Incrementor, 0x386b732f205fd34c97c5914ddd0f7356c5b923229b1cb39e84acd762d62e69c6);
abi.initialize(0); // comment this line out to just increment without initializing
abi.increment(5);
abi.increment(5);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
script;
use std::{chain::auth::caller_is_external, constants::NATIVE_ASSET_ID};
use auth_testing_abi::AuthTesting;
use std::assert::assert;

// should be false in the case of a script
fn main() -> bool {
let caller = abi(AuthTesting, 0x4bc450bf26a5ebca955ed8e58ca281bcba64065a802a2b1cfa5cdefdeec1610e);
caller.returns_gm_one()
let caller = abi(AuthTesting, 0x8c65dd66e3d56a405b5cb329ade3a36e961f4e23038fa3bb3d066feebbf39c1f);
let result = caller.returns_gm_one();
assert(result);
result
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "caller_context_test"

[dependencies]
std = { path = "../../../../../../../sway-lib-std" }
context_testing_abi = { path = "../../test_abis/context_testing_abi" }
std = { path = "../../../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ use context_testing_abi::*;
fn main() -> bool {
let gas: u64 = 1000;
let amount: u64 = 11;
let other_contract_id = ~ContractId::from(0x285dafd64feb42477cfb3da8193ceb28b5f5277c17591d7c10000661cacdd0c9);
let other_contract_id = ~ContractId::from(0x3915399a401876c5145f3d9ed931ca8cc8c98cb9febda445d4fe2ef893151589);
let native_asset_id = ~ContractId::from(NATIVE_ASSET_ID);

// contract ID for sway/test/src/e2e_vm_tests/test_programs/balance_test_contract
let deployed_contract_id = 0xa835193dabf3fe80c0cb62e2ecc424f5ac03bc7f5c896ecc4bd2fd06cc434322;

let test_contract = abi(ContextTesting, 0x285dafd64feb42477cfb3da8193ceb28b5f5277c17591d7c10000661cacdd0c9);
let test_contract = abi(ContextTesting, other_contract_id.into());

// test Context::contract_id():
let returned_contract_id = test_contract.get_id {
gas: gas, coins: 0, asset_id: NATIVE_ASSET_ID
}
();
assert(returned_contract_id.into() == deployed_contract_id);
assert(returned_contract_id.into() == other_contract_id.into());

// @todo set up a test contract to mint some tokens for testing balances.
// test Context::this_balance():
Expand All @@ -35,8 +32,11 @@ fn main() -> bool {
(native_asset_id, other_contract_id);
assert(returned_contract_balance == 0);

// The checks below don't work (AssertIdNotFound). The test should be
// updated to forward coins that are actually available.

// test Context::msg_value():
let returned_amount = test_contract.get_amount {
/*let returned_amount = test_contract.get_amount {
gas: gas, coins: amount, asset_id: NATIVE_ASSET_ID
}
();
Expand All @@ -52,18 +52,18 @@ fn main() -> bool {
// test Context::msg_gas():
// @todo expect the correct gas here... this should fail using `1000`
let gas = test_contract.get_gas {
gas: gas, coins: amount, asset_id: NATIVE_ASSET_ID
gas: gas, coins: 0, asset_id: NATIVE_ASSET_ID
}
();
assert(gas == 1000);
// test Context::global_gas():
// @todo expect the correct gas here... this should fail using `1000`
let global_gas = test_contract.get_global_gas {
gas: gas, coins: amount, asset_id: NATIVE_ASSET_ID
gas: gas, coins: 0, asset_id: NATIVE_ASSET_ID
}
();
assert(global_gas == 1000);
assert(global_gas == 1000);*/

true
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
[[package]]
name = 'call_basic_storage'
dependencies = [
'std git+http://github.com/FuelLabs/sway-lib-std?reference=master#a1d77e1140d1b57ee18cc914d320dc7ffdff98fd',
'std',
'storage_access_abi',
]

[[package]]
name = 'core'
source = 'git+https://github.com/FuelLabs/sway-lib-core?reference=master#082bc8eb0616586ac0000825bfe6e9d47b0c713f'
dependencies = []

[[package]]
name = 'std'
source = 'git+http://github.com/FuelLabs/sway-lib-std?reference=master#a1d77e1140d1b57ee18cc914d320dc7ffdff98fd'
dependencies = ['core git+https://github.com/FuelLabs/sway-lib-core?reference=master#082bc8eb0616586ac0000825bfe6e9d47b0c713f']
dependencies = ['core']

[[package]]
name = 'storage_access_abi'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "call_basic_storage"

[dependencies]
std = { git = "http://github.com/FuelLabs/sway-lib-std" }
std = { path = "../../../../../../../sway-lib-std" }
storage_access_abi = { path = "../../test_abis/storage_access_abi" }
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
script;
use storage_access_abi::{S, StorageAccess, T};
use std::chain::*;
use std::assert::assert;

fn main() -> bool {
let contract_id = 0x19280009c101a694ec13061a4d1853826dd04ec5594a0ab05fd275904c2e4dbf;
let contract_id = 0x1c305447488d8da2c5bd6b025222970b699edd84aa405f15cace2b33a13ddaf4;
let caller = abi(StorageAccess, contract_id);

// Test 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
script;

// use std::constants::ETH_ID;
use std::assert::assert;
use std::address::Address;
use std::context::balance_of;
Expand All @@ -18,13 +17,13 @@ fn main() -> bool {
let default_gas = 1_000_000_000_000;

// the deployed fuel_coin Contract_Id:
let fuelcoin_id = ~ContractId::from(0xff95564b8f788b6a2a884813eadfff2dbfe008a881008e7b298ce14208a73864);
let fuelcoin_id = ~ContractId::from(0x9ebec04226fdd4c962dc0f299da0555d180e3d60e39610a49613512a9846316a);

// contract ID for sway/test/src/e2e_vm_tests/test_programs/balance_test_contract
let balance_test_id = ~ContractId::from(0xa835193dabf3fe80c0cb62e2ecc424f5ac03bc7f5c896ecc4bd2fd06cc434322);
// contract ID for sway/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/balance_test_contract/
let balance_test_id = ~ContractId::from(0xb4c0d8c9056c0cde34b66e7e4e3f361d927d26ffdc16c2645dd0e2699bc96cad);

// todo: use correct type ContractId
let fuel_coin = abi(TestFuelCoin, 0xff95564b8f788b6a2a884813eadfff2dbfe008a881008e7b298ce14208a73864);
let fuel_coin = abi(TestFuelCoin, fuelcoin_id.into());

let mut fuelcoin_balance = balance_of(fuelcoin_id, fuelcoin_id);
assert(fuelcoin_balance == 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
[[package]]
name = 'context_testing_abi'
dependencies = ['std git+https://github.com/FuelLabs/sway-lib-std?reference=master#7b973a638d5220228be616f1f89a249846001549']
dependencies = ['std']

[[package]]
name = 'core'
source = 'git+https://github.com/FuelLabs/sway-lib-core?reference=master#30274cf817c1848e28f984c2e8703eb25e7a3a44'
dependencies = []

[[package]]
name = 'std'
source = 'git+https://github.com/FuelLabs/sway-lib-std?reference=master#7b973a638d5220228be616f1f89a249846001549'
dependencies = ['core git+https://github.com/FuelLabs/sway-lib-core?reference=master#30274cf817c1848e28f984c2e8703eb25e7a3a44']
dependencies = ['core']
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ pub struct S {
x: u64,
y: u64,
z: b256,
t: T
t: T,
}

pub struct T {
x: u64,
y: u64,
z: b256
z: b256,
}

abi StorageAccess {
// Setters
fn set_x(x: u64) ;
fn set_x(x: u64);
fn set_y(y: b256);
fn set_s(s: S);
fn set_s_dot_t(t: T);
Expand All @@ -25,7 +25,7 @@ abi StorageAccess {
fn set_s_dot_t_dot_x(a: u64);
fn set_s_dot_t_dot_y(b: u64);
fn set_s_dot_t_dot_z(c: b256);

// Getters
fn get_x() -> u64;
fn get_y() -> b256;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
[[package]]
name = 'core'
source = 'git+https://github.com/FuelLabs/sway-lib-core?reference=master#30274cf817c1848e28f984c2e8703eb25e7a3a44'
dependencies = []

[[package]]
name = 'std'
source = 'git+https://github.com/FuelLabs/sway-lib-std?reference=master#7b973a638d5220228be616f1f89a249846001549'
dependencies = ['core git+https://github.com/FuelLabs/sway-lib-core?reference=master#30274cf817c1848e28f984c2e8703eb25e7a3a44']
dependencies = ['core']

[[package]]
name = 'test_fuel_coin_abi'
dependencies = ['std git+https://github.com/FuelLabs/sway-lib-std?reference=master#7b973a638d5220228be616f1f89a249846001549']
dependencies = ['std']
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library test_fuel_coin_abi;

use std::address::Address;
use std::contract_id::ContractId;

abi TestFuelCoin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "auth_testing_contract"

[dependencies]
std = { path = "../../../../../../../sway-lib-std" }
auth_testing_abi = { path = "../../test_abis/auth_testing_abi" }
std = { path = "../../../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "balance_test_contract"

[dependencies]
balance_test_abi = { path = "../../test_abis/balance_test_abi" }
std = { path = "../../../../../../../sway-lib-std" }
balance_test_abi = { path = "../../test_abis/balance_test_abi"}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
contract;

use std::context::*;
use balance_test_abi::BalanceTest;

impl BalanceTest for Contract {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "basic_storage"

[dependencies]
std = { path = "../../../../../../../sway-lib-std" }
basic_storage_abi = { path = "../../test_abis/basic_storage_abi" }
std = { path = "../../../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
contract;
use std::storage::*;
use std::hash::*;
use basic_storage_abi::*;

impl StoreU64 for Contract {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "context_testing_contract"

[dependencies]
context_testing_abi = { path = "../../test_abis/context_testing_abi" }
std = { path = "../../../../../../../sway-lib-std" }
context_testing_abi = { path = "../../test_abis/context_testing_abi"}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contract;

use std::{context::{*, call_frames::*, registers::global_gas}, contract_id::ContractId};
use std::{context::{balance_of, call_frames::{contract_id, msg_asset_id}, gas, msg_amount, registers::global_gas, this_balance}, contract_id::ContractId};
use context_testing_abi::*;

impl ContextTesting for Contract {
Expand Down

This file was deleted.

Loading

0 comments on commit 56b3eb9

Please sign in to comment.