forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ABI impl methods part of contract interface (FuelLabs#4843)
Fixes FuelLabs#4841 ## Description ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
- Loading branch information
1 parent
b33b63c
commit 5e04dfa
Showing
26 changed files
with
237 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
.../src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_method_duplicate/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[[package]] | ||
name = 'abi_impl_method_duplicate' | ||
source = 'member' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-DA324EF751E6D833' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-DA324EF751E6D833' | ||
dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
.../src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_method_duplicate/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
name = "abi_impl_method_duplicate" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
10 changes: 10 additions & 0 deletions
10
...rc/e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_method_duplicate/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
contract; | ||
|
||
abi MyAbi | ||
{ | ||
// no interface methods | ||
} | ||
{ | ||
fn method() -> u64 { 42 } | ||
fn method() -> u64 { 43 } // error: duplicate impl method | ||
} |
5 changes: 5 additions & 0 deletions
5
.../src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_method_duplicate/test.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
category = "fail" | ||
|
||
# check: $()error | ||
# check: $()fn method() -> u64 { 43 } // error: duplicate impl method | ||
# check: $()Name "method" is defined multiple times. |
13 changes: 13 additions & 0 deletions
13
...ts/test_programs/should_pass/test_abis/abi_impl_method_shadows_interface_method/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[[package]] | ||
name = 'abi_impl_method_shadows_interface_method' | ||
source = 'member' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-4058F74E887BDDB9' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-4058F74E887BDDB9' | ||
dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
...ts/test_programs/should_pass/test_abis/abi_impl_method_shadows_interface_method/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
name = "abi_impl_method_shadows_interface_method" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
10 changes: 10 additions & 0 deletions
10
.../test_programs/should_pass/test_abis/abi_impl_method_shadows_interface_method/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
contract; | ||
|
||
abi MyAbi | ||
{ | ||
fn method() -> u64; | ||
} | ||
{ | ||
// impl methods cannot shadow interface methods | ||
fn method() -> u64 { 42 } | ||
} |
5 changes: 5 additions & 0 deletions
5
...ts/test_programs/should_pass/test_abis/abi_impl_method_shadows_interface_method/test.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
category = "fail" | ||
|
||
# check: $()error | ||
# check: $()fn method() -> u64 { 42 } | ||
# check: $()Name "method" is defined multiple times. |
13 changes: 13 additions & 0 deletions
13
.../src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_methods_callable/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[[package]] | ||
name = 'abi_impl_methods_callable' | ||
source = 'member' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-214E8589AEAE48E5' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-214E8589AEAE48E5' | ||
dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
.../src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_methods_callable/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
name = "abi_impl_methods_callable" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
14 changes: 14 additions & 0 deletions
14
...rc/e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_methods_callable/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
contract; | ||
|
||
abi MyAbi { } | ||
{ | ||
fn impl_method() -> u64 { 42 } | ||
} | ||
|
||
impl MyAbi for Contract { } | ||
|
||
#[test] | ||
fn tests() { | ||
let caller = abi(MyAbi, CONTRACT_ID); | ||
assert(caller.impl_method() == 42) | ||
} |
1 change: 1 addition & 0 deletions
1
.../src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_methods_callable/test.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
category = "unit_tests_pass" |
3 changes: 3 additions & 0 deletions
3
...c/e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_methods_in_json_abi/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[[package]] | ||
name = 'abi_impl_methods_in_json_abi' | ||
source = 'member' |
6 changes: 6 additions & 0 deletions
6
...c/e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_methods_in_json_abi/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[project] | ||
name = "abi_impl_methods_in_json_abi" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
implicit-std = false |
35 changes: 35 additions & 0 deletions
35
...sts/test_programs/should_pass/test_abis/abi_impl_methods_in_json_abi/json_abi_oracle.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"configurables": [], | ||
"functions": [ | ||
{ | ||
"attributes": null, | ||
"inputs": [], | ||
"name": "interface_method", | ||
"output": { | ||
"name": "", | ||
"type": 0, | ||
"typeArguments": null | ||
} | ||
}, | ||
{ | ||
"attributes": null, | ||
"inputs": [], | ||
"name": "impl_method", | ||
"output": { | ||
"name": "", | ||
"type": 0, | ||
"typeArguments": null | ||
} | ||
} | ||
], | ||
"loggedTypes": [], | ||
"messagesTypes": [], | ||
"types": [ | ||
{ | ||
"components": [], | ||
"type": "()", | ||
"typeId": 0, | ||
"typeParameters": null | ||
} | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
...e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_methods_in_json_abi/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
contract; | ||
|
||
abi MyAbi | ||
{ | ||
fn interface_method(); | ||
} | ||
{ | ||
fn impl_method() { } | ||
} | ||
|
||
impl MyAbi for Contract { | ||
fn interface_method() { } | ||
} |
5 changes: 5 additions & 0 deletions
5
...c/e2e_vm_tests/test_programs/should_pass/test_abis/abi_impl_methods_in_json_abi/test.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
category = "compile" | ||
|
||
validate_abi = true | ||
validate_storage_slots = false | ||
expected_warnings = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/src/sdk-harness/test_projects/abi_impl_methods_callable/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[[package]] | ||
name = 'abi_impl_methods_callable' | ||
source = 'member' |
6 changes: 6 additions & 0 deletions
6
test/src/sdk-harness/test_projects/abi_impl_methods_callable/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[project] | ||
name = "abi_impl_methods_callable" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
implicit-std = false |
31 changes: 31 additions & 0 deletions
31
test/src/sdk-harness/test_projects/abi_impl_methods_callable/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use fuels::accounts::wallet::WalletUnlocked; | ||
use fuels::prelude::*; | ||
|
||
abigen!(Contract( | ||
name = "AbiImplMethodsCallable", | ||
abi = "test_projects/abi_impl_methods_callable/out/debug/abi_impl_methods_callable-abi.json" | ||
)); | ||
|
||
async fn get_abi_impl_methods_callable_instance() -> AbiImplMethodsCallable<WalletUnlocked> { | ||
let wallet = launch_provider_and_get_wallet().await; | ||
let id = Contract::load_from( | ||
"test_projects/abi_impl_methods_callable/out/debug/abi_impl_methods_callable.bin", | ||
LoadConfiguration::default(), | ||
) | ||
.unwrap() | ||
.deploy(&wallet, TxParameters::default()) | ||
.await | ||
.unwrap(); | ||
AbiImplMethodsCallable::new(id.clone(), wallet) | ||
} | ||
|
||
#[tokio::test] | ||
async fn impl_method_test() -> Result<()> { | ||
let instance = get_abi_impl_methods_callable_instance().await; | ||
let contract_methods = instance.methods(); | ||
|
||
let response = contract_methods.impl_method().call().await?; | ||
assert_eq!(42, response.value); | ||
|
||
Ok(()) | ||
} |
13 changes: 13 additions & 0 deletions
13
test/src/sdk-harness/test_projects/abi_impl_methods_callable/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
contract; | ||
|
||
abi MyAbi | ||
{ | ||
fn interface_method(); | ||
} | ||
{ | ||
fn impl_method() -> u64 { 42 } | ||
} | ||
|
||
impl MyAbi for Contract { | ||
fn interface_method() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Add test modules here: | ||
|
||
mod abi_impl_methods_callable; | ||
mod auth; | ||
mod block; | ||
mod call_frames; | ||
|