diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/abi.rs b/sway-core/src/semantic_analysis/ast_node/declaration/abi.rs index 61ba7cd6323..4d354803525 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/abi.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/abi.rs @@ -8,7 +8,10 @@ use crate::{ parsed::*, ty::{self, TyTraitItem}, }, - semantic_analysis::{declaration::insert_supertraits_into_namespace, Mode, TypeCheckContext}, + semantic_analysis::{ + declaration::{insert_supertraits_into_namespace, SupertraitOf}, + Mode, TypeCheckContext, + }, CompileResult, }; @@ -44,7 +47,12 @@ impl ty::TyAbiDecl { // Recursively make the interface surfaces and methods of the // supertraits available to this abi. check!( - insert_supertraits_into_namespace(ctx.by_ref(), contract_type, &supertraits), + insert_supertraits_into_namespace( + ctx.by_ref(), + contract_type, + &supertraits, + SupertraitOf::Abi + ), return err(warnings, errors), warnings, errors diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/declaration.rs b/sway-core/src/semantic_analysis/ast_node/declaration/declaration.rs index 509043a8764..175ef3a70a7 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/declaration.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/declaration.rs @@ -181,12 +181,28 @@ impl ty::TyDecl { warnings, errors ); + // if this ImplTrait implements a trait and not an ABI, + // we insert its methods into the context + // otherwise, if it implements an ABI, we do not + // insert those since we do not allow calling contract methods + // from contract methods + let emp_vec = vec![]; + let impl_trait_items = if let Some(ty::TyDecl::TraitDecl { .. }) = ctx + .namespace + .resolve_call_path(&impl_trait.trait_name) + .ok(&mut warnings, &mut errors) + .cloned() + { + &impl_trait.items + } else { + &emp_vec + }; check!( ctx.namespace.insert_trait_implementation( impl_trait.trait_name.clone(), impl_trait.trait_type_arguments.clone(), impl_trait.implementing_for.type_id, - &impl_trait.items, + impl_trait_items, &impl_trait.span, false, engines, diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs index 06796781db4..e2bcbd87842 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs @@ -649,7 +649,6 @@ fn type_check_trait_implementation( warnings, errors ); - ctx.namespace.insert_trait_implementation( trait_name.clone(), trait_type_arguments.to_vec(), @@ -1303,9 +1302,9 @@ fn handle_supertraits( interface_surface_item_ids.extend(next_interface_supertrait_decl_refs); impld_item_refs.extend(next_these_supertrait_decl_refs); } - Some(ty::TyDecl::AbiDecl { .. }) => errors.push(CompileError::AbiAsSupertrait { - span: supertrait.name.span().clone(), - }), + Some(ty::TyDecl::AbiDecl { .. }) => { + // we allow ABIs as superABIs now + } _ => errors.push(CompileError::TraitNotFound { name: supertrait.name.to_string(), span: supertrait.name.span(), diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/supertrait.rs b/sway-core/src/semantic_analysis/ast_node/declaration/supertrait.rs index 61e576995d5..1aa5bd6fe11 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/supertrait.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/supertrait.rs @@ -8,12 +8,19 @@ use crate::{ EnforceTypeArguments, TypeId, }; +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum SupertraitOf { + Abi, + Trait, +} + /// Recursively insert the interface surfaces and methods from supertraits to /// the given namespace. pub(crate) fn insert_supertraits_into_namespace( mut ctx: TypeCheckContext, type_id: TypeId, supertraits: &[parsed::Supertrait], + supertraits_of: SupertraitOf, ) -> CompileResult<()> { let mut warnings = vec![]; let mut errors = vec![]; @@ -33,13 +40,15 @@ pub(crate) fn insert_supertraits_into_namespace( continue; } - match ctx + let decl = ctx .namespace .resolve_call_path(&supertrait.name) .ok(&mut warnings, &mut errors) - .cloned() - { - Some(ty::TyDecl::TraitDecl { decl_id, .. }) => { + .cloned(); + + match (decl.clone(), supertraits_of) { + // a trait can be a supertrait of either a trait or a an ABI + (Some(ty::TyDecl::TraitDecl { decl_id, .. }), _) => { let mut trait_decl = decl_engine.get_trait(&decl_id); // Right now we don't parse type arguments for supertraits, so @@ -83,16 +92,22 @@ pub(crate) fn insert_supertraits_into_namespace( insert_supertraits_into_namespace( ctx.by_ref(), type_id, - &trait_decl.supertraits + &trait_decl.supertraits, + SupertraitOf::Trait ), continue, warnings, errors ); } - Some(ty::TyDecl::AbiDecl { .. }) => errors.push(CompileError::AbiAsSupertrait { - span: supertrait.name.span().clone(), - }), + // an ABI can only be a superABI of an ABI + (Some(ty::TyDecl::AbiDecl { decl_id: _, .. }), SupertraitOf::Abi) => {} + // an ABI cannot be a supertrait of a trait + (Some(ty::TyDecl::AbiDecl { .. }), SupertraitOf::Trait) => { + errors.push(CompileError::AbiAsSupertrait { + span: supertrait.name.span().clone(), + }) + } _ => errors.push(CompileError::TraitNotFound { name: supertrait.name.to_string(), span: supertrait.name.span(), diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/trait.rs b/sway-core/src/semantic_analysis/ast_node/declaration/trait.rs index 823a47a09ba..969385705f0 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/trait.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/trait.rs @@ -14,7 +14,10 @@ use crate::{ ty::{self, TyImplItem, TyTraitItem}, CallPath, }, - semantic_analysis::{declaration::insert_supertraits_into_namespace, Mode, TypeCheckContext}, + semantic_analysis::{ + declaration::{insert_supertraits_into_namespace, SupertraitOf}, + Mode, TypeCheckContext, + }, type_system::*, }; @@ -65,7 +68,12 @@ impl ty::TyTraitDecl { // Recursively make the interface surfaces and methods of the // supertraits available to this trait. check!( - insert_supertraits_into_namespace(ctx.by_ref(), self_type, &supertraits), + insert_supertraits_into_namespace( + ctx.by_ref(), + self_type, + &supertraits, + SupertraitOf::Trait + ), return err(warnings, errors), warnings, errors diff --git a/sway-core/src/type_system/ast_elements/trait_constraint.rs b/sway-core/src/type_system/ast_elements/trait_constraint.rs index de8875be1f7..6fa5d0e655d 100644 --- a/sway-core/src/type_system/ast_elements/trait_constraint.rs +++ b/sway-core/src/type_system/ast_elements/trait_constraint.rs @@ -10,7 +10,10 @@ use crate::{ engine_threading::*, error::*, language::{parsed::Supertrait, ty, CallPath}, - semantic_analysis::{declaration::insert_supertraits_into_namespace, TypeCheckContext}, + semantic_analysis::{ + declaration::{insert_supertraits_into_namespace, SupertraitOf}, + TypeCheckContext, + }, type_system::priv_prelude::*, types::*, CompileResult, @@ -220,7 +223,8 @@ impl TraitConstraint { insert_supertraits_into_namespace( ctx.by_ref(), type_id, - &trait_decl.supertraits + &trait_decl.supertraits, + SupertraitOf::Trait ), return err(warnings, errors), warnings, diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/Forc.lock new file mode 100644 index 00000000000..e79965bce27 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/Forc.lock @@ -0,0 +1,3 @@ +[[package]] +name = 'superabi_contract_call1' +source = 'member' diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/Forc.toml new file mode 100644 index 00000000000..353a7868099 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/Forc.toml @@ -0,0 +1,6 @@ +[project] +name = "superabi_contract_call1" +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/src/main.sw new file mode 100644 index 00000000000..8d48d17ef87 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/src/main.sw @@ -0,0 +1,12 @@ +contract; + +abi MySuperAbi { + fn super_abi_method(); +} + +abi MyAbi : MySuperAbi { + fn abi_method(); +} { + // this must fail, because contract methods cannot call each other + fn foo() { Self::super_abi_method() } +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/test.toml new file mode 100644 index 00000000000..57e8ca1c4bd --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call1/test.toml @@ -0,0 +1,3 @@ +category = "fail" + +# check: $()No method named "super_abi_method" found for type "contract". \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/Forc.lock new file mode 100644 index 00000000000..3606f81c5ad --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/Forc.lock @@ -0,0 +1,3 @@ +[[package]] +name = 'superabi_contract_call2' +source = 'member' diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/Forc.toml new file mode 100644 index 00000000000..eed47f3e217 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/Forc.toml @@ -0,0 +1,6 @@ +[project] +name = "superabi_contract_call2" +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/src/main.sw new file mode 100644 index 00000000000..c04a4f86a67 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/src/main.sw @@ -0,0 +1,18 @@ +contract; + +abi MySuperAbi { + fn super_abi_method(); +} + +abi MyAbi : MySuperAbi { + fn abi_method(); +} + +impl MySuperAbi for Contract { + fn super_abi_method() { } +} + +impl MyAbi for Contract { + // this must fail, because contract methods cannot call each other + fn abi_method() { Self::super_abi_method() } +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/test.toml new file mode 100644 index 00000000000..57e8ca1c4bd --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_contract_call2/test.toml @@ -0,0 +1,3 @@ +category = "fail" + +# check: $()No method named "super_abi_method" found for type "contract". \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/Forc.lock new file mode 100644 index 00000000000..9d6fa47144b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/Forc.lock @@ -0,0 +1,3 @@ +[[package]] +name = 'superabi_trait' +source = 'member' diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/Forc.toml new file mode 100644 index 00000000000..1b2884538a9 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/Forc.toml @@ -0,0 +1,6 @@ +[project] +name = "superabi_trait" +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/json_abi_oracle.json new file mode 100644 index 00000000000..c0ff35e67b8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/json_abi_oracle.json @@ -0,0 +1,35 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "bar", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + }, + { + "attributes": null, + "inputs": [], + "name": "baz", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": [], + "type": "()", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/src/main.sw new file mode 100644 index 00000000000..b6e9f9c2efc --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/src/main.sw @@ -0,0 +1,10 @@ +contract; + +abi MySuperAbi { + fn super_abi_method(); +} + +// error: traits cannot have superABIs +trait MyAbi : MySuperAbi { + fn abi_method(); +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/test.toml new file mode 100644 index 00000000000..b4081846c6c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_trait/test.toml @@ -0,0 +1,3 @@ +category = "fail" + +# check: $()A trait cannot be a subtrait of an ABI. \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/Forc.lock new file mode 100644 index 00000000000..79d98d60811 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/Forc.lock @@ -0,0 +1,3 @@ +[[package]] +name = 'superabi_unimplemented' +source = 'member' diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/Forc.toml new file mode 100644 index 00000000000..4a2b0743a0e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/Forc.toml @@ -0,0 +1,6 @@ +[project] +name = "superabi_unimplemented" +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/json_abi_oracle.json new file mode 100644 index 00000000000..c0ff35e67b8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/json_abi_oracle.json @@ -0,0 +1,35 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "bar", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + }, + { + "attributes": null, + "inputs": [], + "name": "baz", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": [], + "type": "()", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/src/main.sw new file mode 100644 index 00000000000..5accb3fca24 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/src/main.sw @@ -0,0 +1,18 @@ +contract; + +abi MySuperAbi { + fn super_abi_method(); +} + +abi MyAbi : MySuperAbi { + fn abi_method(); +} + +// The implementation of MyAbi for Contract must also implement MySuperAbi +// impl MySuperAbi for Contract { +// ... +// } + +impl MyAbi for Contract { + fn abi_method() { } +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/test.toml new file mode 100644 index 00000000000..69e9e09400a --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/superabi_unimplemented/test.toml @@ -0,0 +1,3 @@ +category = "fail" + +# check: $()Trait "MySuperAbi" is not implemented for type "contract". \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/superabi/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/superabi/Forc.lock new file mode 100644 index 00000000000..fb64cd34101 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/superabi/Forc.lock @@ -0,0 +1,3 @@ +[[package]] +name = 'superabi' +source = 'member' diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/superabi/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/superabi/Forc.toml new file mode 100644 index 00000000000..53fcd4b8006 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/superabi/Forc.toml @@ -0,0 +1,6 @@ +[project] +name = "superabi" +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/superabi/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/superabi/json_abi_oracle.json new file mode 100644 index 00000000000..0d8645f9a70 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/superabi/json_abi_oracle.json @@ -0,0 +1,35 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "super_abi_method", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + }, + { + "attributes": null, + "inputs": [], + "name": "abi_method", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": [], + "type": "()", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/superabi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/superabi/src/main.sw new file mode 100644 index 00000000000..1c603a111a4 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/superabi/src/main.sw @@ -0,0 +1,18 @@ +contract; + +abi MySuperAbi { + fn super_abi_method(); +} + +abi MyAbi : MySuperAbi { + fn abi_method(); +} + +impl MySuperAbi for Contract { + fn super_abi_method() { } +} + +// The implementation of MyAbi for Contract must also implement MySuperAbi +impl MyAbi for Contract { + fn abi_method() { } +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/superabi/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/superabi/test.toml new file mode 100644 index 00000000000..f9c674d3e0e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/superabi/test.toml @@ -0,0 +1,2 @@ +category = "compile" +validate_abi = true \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/Forc.lock new file mode 100644 index 00000000000..9ef81a4784c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/Forc.lock @@ -0,0 +1,3 @@ +[[package]] +name = 'superabi_diamond' +source = 'member' diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/Forc.toml new file mode 100644 index 00000000000..85b374ce94f --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/Forc.toml @@ -0,0 +1,6 @@ +[project] +name = "superabi_diamond" +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/json_abi_oracle.json new file mode 100644 index 00000000000..cf4df756ad6 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/json_abi_oracle.json @@ -0,0 +1,55 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "top", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + }, + { + "attributes": null, + "inputs": [], + "name": "left", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + }, + { + "attributes": null, + "inputs": [], + "name": "right", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + }, + { + "attributes": null, + "inputs": [], + "name": "bottom", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": [], + "type": "()", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/src/main.sw new file mode 100644 index 00000000000..0b87dc57a48 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/src/main.sw @@ -0,0 +1,39 @@ +contract; + +/// Top +/// / \ +/// Left Right +/// \ / +/// Bottom + +abi Top { + fn top(); +} + +abi Left : Top { + fn left(); +} + +abi Right : Top { + fn right(); +} + +abi Bottom : Left + Right { + fn bottom(); +} + +impl Top for Contract { + fn top() { } +} + +impl Left for Contract { + fn left() { } +} + +impl Right for Contract { + fn right() { } +} + +impl Bottom for Contract { + fn bottom() { } +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/test.toml new file mode 100644 index 00000000000..f9c674d3e0e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/superabi_diamond/test.toml @@ -0,0 +1,2 @@ +category = "compile" +validate_abi = true \ No newline at end of file diff --git a/test/src/sdk-harness/test_projects/harness.rs b/test/src/sdk-harness/test_projects/harness.rs index fac09311f03..d352c54b40f 100644 --- a/test/src/sdk-harness/test_projects/harness.rs +++ b/test/src/sdk-harness/test_projects/harness.rs @@ -30,6 +30,7 @@ mod storage; mod storage_bytes; mod storage_map; mod storage_vec; +mod superabi; mod token_ops; mod tx_fields; mod type_aliases; diff --git a/test/src/sdk-harness/test_projects/superabi/Forc.lock b/test/src/sdk-harness/test_projects/superabi/Forc.lock new file mode 100644 index 00000000000..d08bca6eeda --- /dev/null +++ b/test/src/sdk-harness/test_projects/superabi/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = 'core' +source = 'path+from-root-7293F2DA9B0C5621' + +[[package]] +name = 'std' +source = 'path+from-root-7293F2DA9B0C5621' +dependencies = ['core'] + +[[package]] +name = 'superabi' +source = 'member' +dependencies = ['std'] diff --git a/test/src/sdk-harness/test_projects/superabi/Forc.toml b/test/src/sdk-harness/test_projects/superabi/Forc.toml new file mode 100644 index 00000000000..c42f6770986 --- /dev/null +++ b/test/src/sdk-harness/test_projects/superabi/Forc.toml @@ -0,0 +1,8 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "superabi" + +[dependencies] +std = { path = "../../../../../sway-lib-std" } diff --git a/test/src/sdk-harness/test_projects/superabi/mod.rs b/test/src/sdk-harness/test_projects/superabi/mod.rs new file mode 100644 index 00000000000..7bd44ceb1b2 --- /dev/null +++ b/test/src/sdk-harness/test_projects/superabi/mod.rs @@ -0,0 +1,45 @@ +use fuels::prelude::*; + +abigen!(Contract( + name = "SuperAbiTestContract", + abi = "test_projects/superabi/out/debug/superabi-abi.json" +)); + +async fn get_superabi_instance() -> (SuperAbiTestContract, ContractId) { + let wallet = launch_provider_and_get_wallet().await; + let id = Contract::deploy( + "test_projects/superabi/out/debug/superabi.bin", + &wallet, + TxParameters::default(), + StorageConfiguration::with_storage_path(Some( + "test_projects/superabi/out/debug/superabi-storage_slots.json".to_string(), + )), + ) + .await + .unwrap(); + let instance = SuperAbiTestContract::new(id.clone(), wallet); + + (instance, id.into()) +} + +#[tokio::test] +async fn abi_test() -> Result<()> { + let (instance, _id) = get_superabi_instance().await; + let contract_methods = instance.methods(); + + let response = contract_methods.abi_test().call().await?; + assert_eq!(42, response.value); + + Ok(()) +} + +#[tokio::test] +async fn superabi_test() -> Result<()> { + let (instance, _id) = get_superabi_instance().await; + let contract_methods = instance.methods(); + + let response = contract_methods.superabi_test().call().await?; + assert_eq!(48, response.value); + + Ok(()) +} diff --git a/test/src/sdk-harness/test_projects/superabi/src/main.sw b/test/src/sdk-harness/test_projects/superabi/src/main.sw new file mode 100644 index 00000000000..3e41f5b4505 --- /dev/null +++ b/test/src/sdk-harness/test_projects/superabi/src/main.sw @@ -0,0 +1,21 @@ +contract; + +abi MySuperAbi { + fn superabi_test() -> u8; +} + +abi MyContract : MySuperAbi { + fn abi_test() -> u8; +} + +impl MySuperAbi for Contract { + fn superabi_test() -> u8 { + 41 + } +} + +impl MyContract for Contract { + fn abi_test() -> u8 { + 42 + } +}