-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(e2e): add increment contract FE-893 (#425)
- Loading branch information
Showing
17 changed files
with
238 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: 'Forc Setup' | ||
|
||
inputs: | ||
forc-components: | ||
default: 'forc@0.65.2, fuel-core@0.39.0' | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Install Fuel toolchain | ||
uses: FuelLabs/action-fuel-toolchain@v0.6.0 | ||
with: | ||
name: fuel-bridge | ||
components: ${{ inputs.forc-components }} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out | ||
target |
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 @@ | ||
[[package]] | ||
name = "core" | ||
source = "path+from-root-4BA3A18A2D620E67" | ||
|
||
[[package]] | ||
name = "custom_asset" | ||
source = "member" | ||
dependencies = [ | ||
"standards git+https://github.com/FuelLabs/sway-standards?tag=v0.4.1#0a6f3ba0bce036a0ce61f15ed4480c71af32d3aa", | ||
"std", | ||
"sway_libs", | ||
] | ||
|
||
[[package]] | ||
name = "standards" | ||
source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.4.1#0a6f3ba0bce036a0ce61f15ed4480c71af32d3aa" | ||
dependencies = ["std"] | ||
|
||
[[package]] | ||
name = "standards" | ||
source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.4.3#6f63eb7dff2458a7d976184e565b5cbf26f61da2" | ||
dependencies = ["std"] | ||
|
||
[[package]] | ||
name = "std" | ||
source = "git+https://github.com/fuellabs/sway?tag=v0.64.0#2156bfbbee01ffb85bfca2aae8f185f8e7c715a4" | ||
dependencies = ["core"] | ||
|
||
[[package]] | ||
name = "sway_libs" | ||
source = "git+https://github.com/FuelLabs/sway-libs?tag=v0.21.0#6a227ed34c86fe1ebd334dbdfeccf66c43e3915b" | ||
dependencies = [ | ||
"standards git+https://github.com/FuelLabs/sway-standards?tag=v0.4.3#6f63eb7dff2458a7d976184e565b5cbf26f61da2", | ||
"std", | ||
] |
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,9 @@ | ||
[project] | ||
authors = ["Matt Auer"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "custom_asset" | ||
|
||
[dependencies] | ||
standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.4.1" } | ||
sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.21.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
contract; | ||
|
||
abi CounterContract { | ||
#[storage(read)] | ||
fn get_count() -> u64; | ||
|
||
#[storage(read, write)] | ||
fn increment_counter() -> u64; | ||
} | ||
|
||
storage { | ||
counter: u64 = 0, | ||
} | ||
|
||
impl CounterContract for Contract { | ||
#[storage(read)] | ||
fn get_count() -> u64 { | ||
storage.counter.try_read().unwrap_or(0) | ||
} | ||
|
||
#[storage(read, write)] | ||
fn increment_counter() -> u64 { | ||
let incremented = storage.counter.try_read().unwrap_or(0) + 1; | ||
storage.counter.write(incremented); | ||
incremented | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { existsSync, readFileSync, writeFileSync } from 'node:fs'; | ||
import { join } from 'node:path'; | ||
import { createConfig } from 'fuels'; | ||
|
||
export default createConfig({ | ||
output: './src/contracts', | ||
contracts: ['./contracts/custom_asset'], | ||
forcBuildFlags: ['--release'], | ||
privateKey: | ||
'0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298', | ||
providerUrl: 'http://localhost:4000/v1/graphql', | ||
onDeploy: (_, contracts) => { | ||
const contractIdsPath = join(__dirname, './src/contract-ids.json'); | ||
let contractIds = {}; | ||
if (existsSync(contractIdsPath)) { | ||
contractIds = JSON.parse( | ||
readFileSync(contractIdsPath, 'utf8').toString(), | ||
); | ||
} | ||
|
||
contractIds[process.env.CONTRACT_NAME || 'contract'] = | ||
contracts[0].contractId; | ||
writeFileSync(contractIdsPath, JSON.stringify(contractIds, null, 2)); | ||
}, | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
|
||
# Get the directory where the script is located | ||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/scripts" | ||
|
||
echo "Build contracts" | ||
pnpm fuels build | ||
|
||
echo "Deploy contract" | ||
pnpm fuels deploy | ||
|
||
# Define paths for the input and output files | ||
CONTRACT_IDS_PATH="$SCRIPT_DIR/../src/contracts/contract-ids.json" | ||
OUTPUT_PATH_APP="$SCRIPT_DIR/../../../examples/react-app/src/types/contract-ids-local.json" | ||
|
||
# Ensure the output directory exists | ||
mkdir -p "$(dirname "$OUTPUT_PATH_APP")" | ||
|
||
# Debug: Show paths and check if CONTRACT_IDS_PATH exists | ||
echo "SCRIPT_DIR is: $SCRIPT_DIR" | ||
echo "CONTRACT_IDS_PATH is: $CONTRACT_IDS_PATH" | ||
echo "OUTPUT_PATH_APP is: $OUTPUT_PATH_APP" | ||
|
||
# Check if the contract-ids.json file exists and display its contents | ||
if [ -f "$CONTRACT_IDS_PATH" ]; then | ||
echo "Found contract-ids.json at $CONTRACT_IDS_PATH" | ||
cat "$CONTRACT_IDS_PATH" | ||
else | ||
echo "Error: $CONTRACT_IDS_PATH not found." | ||
exit 1 | ||
fi | ||
|
||
# Extract the customAsset contract ID from contract-ids.json | ||
CONTRACT_ID=$(jq -r '.customAsset // empty' "$CONTRACT_IDS_PATH") | ||
|
||
# Check if CONTRACT_ID was successfully extracted | ||
if [ -z "$CONTRACT_ID" ]; then | ||
echo "Error: Contract ID for 'customAsset' not found in $CONTRACT_IDS_PATH" | ||
exit 1 | ||
fi | ||
|
||
# Save the contract ID to contract-ids-local.json | ||
jq -n --arg counter "$CONTRACT_ID" '{ "counter": $counter }' > "$OUTPUT_PATH_APP" | ||
echo "Saved contract ID as 'counter' in contract-ids-local.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,20 @@ | ||
#!/bin/bash | ||
|
||
# Get the directory where the script is located | ||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
||
echo "Build contracts" | ||
pnpm fuels build | ||
|
||
echo "Deploy contract" | ||
pnpm fuels deploy | ||
|
||
CONTRACT_IDS_PATH="$SCRIPT_DIR/../src/contracts/contract-ids.json" | ||
OUTPUT_PATH_APP="$SCRIPT_DIR/../../../examples/react-app/src/types/contract-ids-local.json" | ||
|
||
mkdir -p "$(dirname "$OUTPUT_PATH_APP")" | ||
|
||
CONTRACT_ID=$(jq -r '.customAsset // empty' "$CONTRACT_IDS_PATH") | ||
|
||
jq -n --arg counter "$CONTRACT_ID" '{ "counter": $counter }' > "$OUTPUT_PATH_APP" | ||
echo "Saved contract ID as 'counter' in contract-ids-local.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,3 @@ | ||
{ | ||
"contract": "0x0000000000000000000000000000000000000000000000000000000000000000" | ||
} |
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 @@ | ||
{ | ||
"customAsset": "0x0000000000000000000000000000000000000000000000000000000000000000" | ||
} |
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 @@ | ||
export * from './contracts'; |