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.
update increment contract to new-style storage (FuelLabs#2336)
* update increment contract to new-style storage * update oracles for test
- Loading branch information
Showing
5 changed files
with
14 additions
and
37 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
2 changes: 0 additions & 2 deletions
2
test/src/e2e_vm_tests/test_programs/should_pass/test_abis/increment_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
20 changes: 0 additions & 20 deletions
20
...vm_tests/test_programs/should_pass/test_contracts/increment_contract/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
7 changes: 6 additions & 1 deletion
7
...est_programs/should_pass/test_contracts/increment_contract/json_storage_slots_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 |
---|---|---|
@@ -1 +1,6 @@ | ||
[] | ||
[ | ||
{ | ||
"key": "f383b0ce51358be57daa3b725fe44acdb2d880604e367199080b4379c41bb6ed", | ||
"value": "0000000000000000000000000000000000000000000000000000000000000000" | ||
} | ||
] |
19 changes: 7 additions & 12 deletions
19
.../src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/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 |
---|---|---|
@@ -1,26 +1,21 @@ | ||
contract; | ||
|
||
use increment_abi::Incrementor; | ||
use std::storage::{get, store}; | ||
|
||
const KEY = 0x0000000000000000000000000000000000000000000000000000000000000000; | ||
storage { | ||
value: u64 = 0, | ||
} | ||
|
||
impl Incrementor for Contract { | ||
#[storage(write)] | ||
fn initialize(initial_value: u64) -> u64 { | ||
store(KEY, initial_value); | ||
initial_value | ||
} | ||
#[storage(read, write)] | ||
fn increment(increment_by: u64) -> u64 { | ||
let new_val = get::<u64>(KEY) + increment_by; | ||
// check that monomorphization doesn't overwrite the type of the above | ||
let dummy = get::<u32>(KEY) + increment_by; | ||
store(KEY, new_val); | ||
let new_val = storage.value + increment_by; | ||
storage.value = new_val; | ||
new_val | ||
} | ||
|
||
#[storage(read)] | ||
fn get() -> u64 { | ||
get::<u64>(KEY) | ||
storage.value | ||
} | ||
} |