Skip to content

Commit

Permalink
Test reference examples under CI (FuelLabs#4583)
Browse files Browse the repository at this point in the history
  • Loading branch information
Braqzen authored May 25, 2023
1 parent 161ae35 commit be7e73a
Show file tree
Hide file tree
Showing 73 changed files with 401 additions and 121 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Build Sway examples workspace
run: cargo run --locked -p forc -- build --locked --path ./examples/Forc.toml

build-reference-examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
- uses: Swatinem/rust-cache@v2
- name: Build Sway examples workspace
run: cargo run --locked -p forc -- build --locked --path ./docs/reference/src/code/Forc.toml

forc-fmt-check-sway-examples:
runs-on: ubuntu-latest
Expand Down
258 changes: 258 additions & 0 deletions docs/reference/src/code/Forc.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
[[package]]
name = 'annotation_style'
source = 'member'
dependencies = ['std']

[[package]]
name = 'annotations'
source = 'member'
dependencies = ['std']

[[package]]
name = 'arrays'
source = 'member'
dependencies = ['std']

[[package]]
name = 'assertions'
source = 'member'
dependencies = ['std']

[[package]]
name = 'asset_operations'
source = 'member'
dependencies = ['std']

[[package]]
name = 'associated-consts'
source = 'member'

[[package]]
name = 'booleans'
source = 'member'
dependencies = ['std']

[[package]]
name = 'bytes'
source = 'member'
dependencies = ['std']

[[package]]
name = 'call'
source = 'member'
dependencies = [
'contract_interface',
'std',
]

[[package]]
name = 'call_data'
source = 'member'
dependencies = ['std']

[[package]]
name = 'comments'
source = 'member'
dependencies = ['std']

[[package]]
name = 'constants'
source = 'member'

[[package]]
name = 'contract_interface'
source = 'member'
dependencies = ['std']

[[package]]
name = 'control_flow'
source = 'member'
dependencies = ['std']

[[package]]
name = 'core'
source = 'path+from-root-B313E39BF6A5D375'

[[package]]
name = 'counter'
source = 'member'
dependencies = ['std']

[[package]]
name = 'empty_storage_init'
source = 'member'
dependencies = ['std']

[[package]]
name = 'enum-advanced'
source = 'member'
dependencies = ['std']

[[package]]
name = 'enum_style'
source = 'member'
dependencies = ['std']

[[package]]
name = 'enums'
source = 'member'
dependencies = ['std']

[[package]]
name = 'fizzbuzz'
source = 'member'
dependencies = ['std']

[[package]]
name = 'functions'
source = 'member'
dependencies = ['std']

[[package]]
name = 'hashing'
source = 'member'
dependencies = ['std']

[[package]]
name = 'interface'
source = 'member'
dependencies = ['std']

[[package]]
name = 'letter_casing'
source = 'member'
dependencies = ['std']

[[package]]
name = 'logging'
source = 'member'
dependencies = ['std']

[[package]]
name = 'my_lib'
source = 'member'
dependencies = ['std']

[[package]]
name = 'my_library'
source = 'member'
dependencies = [
'my_other_library',
'std',
]

[[package]]
name = 'my_other_library'
source = 'member'
dependencies = ['std']

[[package]]
name = 'namespace'
source = 'member'
dependencies = ['std']

[[package]]
name = 'numerics'
source = 'member'
dependencies = ['std']

[[package]]
name = 'ownership'
source = 'member'
dependencies = ['std']

[[package]]
name = 're_entrency'
source = 'member'
dependencies = [
'reentrancy',
'std',
]

[[package]]
name = 'reading_writing_to_storage'
source = 'member'
dependencies = ['std']

[[package]]
name = 'reentrancy'
source = 'git+https://github.com/FuelLabs/sway-libs?tag=v0.10.0#0444499cf24b383eda96ad24c93e3b8bc31ab1b9'
dependencies = ['std']

[[package]]
name = 'simple_predicate'
source = 'member'
dependencies = ['std']

[[package]]
name = 'simple_script'
source = 'member'
dependencies = ['std']

[[package]]
name = 'std'
source = 'git+https://github.com/fuellabs/sway?tag=v0.39.1#e3065657c907225a8fdfe2d2210a7a3bd2b55c73'
dependencies = ['core']

[[package]]
name = 'storage_init'
source = 'member'
dependencies = ['std']

[[package]]
name = 'storage_map'
source = 'member'
dependencies = ['std']

[[package]]
name = 'storage_vec'
source = 'member'
dependencies = ['std']

[[package]]
name = 'store_get'
source = 'member'
dependencies = ['std']

[[package]]
name = 'string_issue'
source = 'member'
dependencies = ['std']

[[package]]
name = 'strings'
source = 'member'
dependencies = ['std']

[[package]]
name = 'struct_shorthand'
source = 'member'
dependencies = ['std']

[[package]]
name = 'structs'
source = 'member'
dependencies = ['std']

[[package]]
name = 'tuples'
source = 'member'
dependencies = ['std']

[[package]]
name = 'variables'
source = 'member'
dependencies = ['std']

[[package]]
name = 'wallet'
source = 'member'
dependencies = [
'interface',
'std',
]

[[package]]
name = 'wallet_example'
source = 'member'
dependencies = ['std']
50 changes: 50 additions & 0 deletions docs/reference/src/code/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[workspace]
members = [
"examples/access-control/ownership",
"examples/counter",
"examples/fizzbuzz",
"examples/wallet_example",
"language/annotations",
"language/built-ins/arrays",
"language/built-ins/booleans",
"language/built-ins/bytes",
"language/built-ins/constants",
"language/built-ins/enums",
"language/built-ins/numerics",
"language/built-ins/strings",
"language/built-ins/structs",
"language/built-ins/tuples",
"language/comments",
"language/control_flow",
"language/functions",
"language/program-types/contracts/interface",
"language/program-types/contracts/wallet",
"language/program-types/libraries/external/my_library",
"language/program-types/libraries/external/my_other_library",
"language/program-types/libraries/internal/my_lib",
"language/program-types/predicates/simple_predicate",
"language/program-types/scripts/simple_script",
"language/style-guide/annotation_style",
"language/style-guide/enum_style",
"language/style-guide/letter_casing",
"language/style-guide/struct_shorthand",
"language/traits/associated-consts",
"language/variables",
"misc/advanced-concepts/enum_advanced",
"misc/known-issues/string_issue",
"operations/assertions",
"operations/asset_operations",
"operations/call_data",
"operations/contract_calling/contract_interface",
"operations/contract_calling/call",
"operations/hashing",
"operations/logging",
"operations/namespace",
"operations/re_entrency",
"operations/storage/empty_storage_init",
"operations/storage/reading_writing_to_storage",
"operations/storage/storage_init",
"operations/storage/storage_map",
"operations/storage/storage_vec",
"operations/storage/store_get",
]
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ abi Ownership {
impl Ownership for Contract {
#[storage(read, write)]
fn set_owner(owner: Option<Identity>) {
assert(storage.owner.is_none() || storage.owner.unwrap() == msg_sender().unwrap());
storage.owner = owner;
assert(storage.owner.read().is_none() || storage.owner.read().unwrap() == msg_sender().unwrap());
storage.owner.write(owner);
}

#[storage(read)]
fn action() {
assert(storage.owner.unwrap() == msg_sender().unwrap());
assert(storage.owner.read().unwrap() == msg_sender().unwrap());
// code
}
}
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/src/code/examples/counter/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ storage {
impl Counter for Contract {
#[storage(read, write)]
fn increment() {
storage.counter += 1;
storage.counter.write(storage.counter.read() + 1);
}

#[storage(read, write)]
fn decrement() {
storage.counter -= 1;
storage.counter.write(storage.counter.read() - 1);
}

#[storage(read)]
fn count() -> u64 {
storage.counter
storage.counter.read()
}
}
// ANCHOR_END: counter
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
authors = ["Fuel Labs <[email protected]>"]
entry = "main.sw"
license = "Apache-2.0"
name = "simple"
name = "wallet_example"

[dependencies]
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ impl Wallet for Contract {
#[storage(read, write)]
fn receive() {
assert(msg_asset_id() == BASE_ASSET_ID);
storage.balance += msg_amount();
storage.balance.write(storage.balance.read() + msg_amount());
}

#[storage(read, write)]
fn send(amount: u64, recipient: Identity) {
assert(msg_sender().unwrap() == Identity::Address(OWNER));
storage.balance -= amount;
storage.balance.write(storage.balance.read() - amount);
transfer(amount, BASE_ASSET_ID, recipient);
}
}
Expand Down
Loading

0 comments on commit be7e73a

Please sign in to comment.