-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new infra for code snippets #2651
Draft
arboleya
wants to merge
101
commits into
master
Choose a base branch
from
aa/feat/infra-for-new-snippets
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+427
−20
Draft
Changes from 84 commits
Commits
Show all changes
101 commits
Select commit
Hold shift + click to select a range
28c0b1c
Starting new code-snippets app
arboleya 48bbcba
Porting getting-started snippets
arboleya 5b4f678
Ignoring new app in changesets
arboleya a45a02a
Adding changeset
arboleya b382460
Ignoring wrapped snippets files (generated)
arboleya a83e65c
Ignore test files trying to import files that haven’t been built yet
arboleya 41c2943
Merge branch 'master' into aa/feat/infra-for-new-snippets
Torres-ssf 596242c
Merge branch 'master' into aa/feat/infra-for-new-snippets
Torres-ssf 89bd596
Using real code/file rather than code-string
arboleya 89348f9
Adding example using `launchTestNode` and `LOCAL_NETWORK_URL` overrides
arboleya 0b790b7
Skipping until forc workspace has at least one member
arboleya 125aaad
Renaming variable
arboleya 3406527
Fixing regex
arboleya 01f8558
Ignoring lint issues individually
arboleya b63c163
Removing from browser group
arboleya 36dbe16
Lintfix
arboleya 663d9ce
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya 9134334
Restoring console after snippet
arboleya 168f124
Keeping wrapper free from weird hacks
arboleya 3dd1e3f
Adding mock utility
arboleya 6ed91e2
Using mocking utility
arboleya 939f9d6
Validating if `nertworkUrl` was properly mocked
arboleya 571e85c
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya f795f00
Mock provider instead?
arboleya 5732d8c
Mocking only for localhost
arboleya 020022f
Adjusting snippets
arboleya 1388057
Wrapping snippet in a try/catch
arboleya 48f1176
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya 98b02e1
Adding blank spaces
arboleya ea01d46
Removing mocking utility
arboleya 2cacdb2
Adding pass-through options for `console.log` calls
arboleya 86205c4
Adding new slot for injecting test node launcher into wrapped snippet
arboleya a6545af
Injecting node launcher for snippets using `LOCAL_NETWORK_URL`
arboleya fd9a886
Trim snippets
arboleya 8295f4f
Cleanup snippets tests
arboleya 70dde7c
Stop ignoring test for `docs-snippets2`
arboleya 45b576b
Re-adding `docs-snippets2` tests to knip ignore list
arboleya 802356a
Using internal builds
arboleya 74f7cef
Fixing ignore rule
arboleya 8c0be15
Adding basic counter Sway project
arboleya 6af5a6a
Improving scripts
arboleya 143d8be
Adding sample env file
arboleya 5a47c48
Standardizing snippets and tests
arboleya c68ea14
Validate env constants existence
arboleya 7a65623
Drafting new snippet
arboleya f2f4133
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya c32a6e9
Adjusting script command
arboleya 0d81092
Removing unnecessary wallet
arboleya 65d6e80
Extacting launcher into another file
arboleya 7ddc250
New API draft
arboleya 28cce95
Syncing env and launcher template
arboleya 47b19bd
Better docs
arboleya f0287c2
Adding new sway script
arboleya 4ac46af
Removing API draft
arboleya e0c319e
Fixing file location
arboleya c647814
Add script to workspace
arboleya 1ebc19d
Improve snippet
arboleya 9c93682
Using new snippets
arboleya 739d78e
Add new API draft
arboleya 3808175
Matching extra blankspace
arboleya a91820f
Ignoring env file
arboleya 7b8bbbb
Adding region marks
arboleya 847c412
Avoid repetition
arboleya 3f756e9
Trim env consts
arboleya 16abcb4
Cleanup
arboleya 094355b
Playing around new API
arboleya a5d3d08
Tidying up
arboleya 501d913
Ignoring experimental file
arboleya 71f0c01
Ignoring generated files in eslint
arboleya ae8fc47
Adjusting wallets count
arboleya 4379cff
Moving chunk around
arboleya b4f2164
Adjusting ignore rule
arboleya 8bf6293
Improving imports manipulation
arboleya 9590341
Adding comments
arboleya 4be8d63
Adjusting template markers
arboleya 88a04b4
Tyop
arboleya 57289fd
Update draft
arboleya 71847b0
Update title
arboleya 2f02691
Adjust deployment usage
arboleya a7fd7e7
Updating example
arboleya 7f8c273
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya 247898c
Removing temp draft
arboleya dfe8eb9
Removing temp draft section
arboleya e73a076
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya e03c3db
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya aa09fbd
Updating broken test
arboleya 0268ef3
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya 5cb05ae
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya afa36c7
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya 6e05237
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya 739ccef
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya dd4d3f8
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya 3c36528
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya 5d85686
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya 9647ccf
Using `NETWORK_URL` across the board
arboleya 85c8cbd
Reword comment
arboleya 1fcdf29
Adding scripts dir to tsconfig
arboleya 3b463d0
Starting with more wallets
arboleya 405b4fd
Merge branch 'master' into aa/feat/infra-for-new-snippets
arboleya 9532319
Automatically generating tests for code snippets
arboleya 00234d6
Forcing assertion failures to throw
arboleya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,4 @@ | ||
--- | ||
--- | ||
|
||
feat: new infra for code snippets |
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,6 @@ | ||
module.exports = { | ||
extends: ['../../.eslintrc.js'], | ||
rules: { | ||
'no-console': 'off', | ||
}, | ||
}; |
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 @@ | ||
src/typegend | ||
*.wrapped.ts |
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 @@ | ||
import { createConfig } from 'fuels'; | ||
|
||
export default createConfig({ | ||
workspace: './sway', | ||
output: './src/typegend', | ||
forcBuildFlags: ['--release'], | ||
forcPath: 'fuels-forc', | ||
fuelCorePath: 'fuels-core', | ||
}); |
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,22 @@ | ||
{ | ||
"name": "@fuel-ts/docs-snippets2", | ||
"version": "0.67.0", | ||
"description": "", | ||
"private": true, | ||
"scripts": { | ||
"build": "run-s wrap:snippets build:forc", | ||
"build:forc": "pnpm fuels build", | ||
"wrap:snippets": "tsx scripts/wrap-snippets.ts", | ||
"pretest": "pnpm build", | ||
"test": "cd ../.. && pnpm run test:filter apps/docs-snippets2" | ||
}, | ||
"dependencies": { | ||
"fuels": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"glob": "^10.2.6" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
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,16 @@ | ||
import { launchTestNode } from 'fuels/test-utils'; | ||
|
||
using node = await launchTestNode({ walletsConfig: { count: 3 } }); | ||
|
||
export const LOCAL_NETWORK_URL = node.provider.url; | ||
|
||
const [w0, w2, w3] = node.wallets; | ||
|
||
export const WALLET_ADDRESS = w0.address; | ||
export const WALLET_PVT_KEY = w0.privateKey; | ||
|
||
export const WALLET_ADDRESS_2 = w2.address; | ||
export const WALLET_PVT_KEY_2 = w2.privateKey; | ||
|
||
export const WALLET_ADDRESS_3 = w3.address; | ||
export const WALLET_PVT_KEY_3 = w3.privateKey; |
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,88 @@ | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
import { globSync } from 'glob'; | ||
import { join } from 'path'; | ||
|
||
const wrapperFnFilepath = join(__dirname, 'wrapper-fn.ts'); | ||
const wrapperFnContents = readFileSync(wrapperFnFilepath, 'utf-8'); | ||
|
||
/** | ||
* Wrap snippet for testing | ||
* @param filepath - Snippet filepath | ||
*/ | ||
export const wrapSnippet = (filepath: string) => { | ||
const snippetContents = readFileSync(filepath, 'utf8'); | ||
|
||
/* | ||
Filter all imports from file. | ||
*/ | ||
const importsReg = /^[\s\S]+from.+['"];/gm; | ||
let imports = snippetContents.match(importsReg)?.toString() ?? ''; | ||
const snippetsNoImports = imports.length ? snippetContents.split(imports)[1] : snippetContents; | ||
|
||
/* | ||
Removes .env file import | ||
*/ | ||
const envImportReg = /import.+\{.+([\s\S]+).+\}.+from.+'\.\.\/env';/gm; | ||
if (envImportReg.test(imports)) { | ||
const allImports = imports.match(envImportReg)?.[0]; | ||
const envImport = `import ${allImports?.split('import ').pop()}`; | ||
imports = imports.replace(envImport, ''); | ||
} | ||
|
||
/* | ||
Inject node launcher & friends | ||
*/ | ||
let nodeLauncher = ''; | ||
const localNetworkReg = /,?\s+LOCAL_NETWORK_URL(\s*,)?/; | ||
if (localNetworkReg.test(imports)) { | ||
/* | ||
Removes `LOCAL_NETWORK_URL` from `fuels` import members | ||
*/ | ||
imports = imports.replace(localNetworkReg, '$1'); | ||
|
||
/* | ||
Adds launchNode import | ||
*/ | ||
imports += `\nimport { launchTestNode } from 'fuels/test-utils'`; | ||
|
||
/* | ||
Injects launched node and env constants | ||
*/ | ||
nodeLauncher = readFileSync(join(__dirname, 'launcher.ts'), 'utf-8') | ||
.replace(/import.*$/gm, '') // ignore file imports | ||
.replace(/export /g, '') // remove export keywords | ||
.trim() // zip | ||
.replace(/\n/g, '\n '); // indent chunk | ||
} | ||
|
||
/* | ||
Format indentation | ||
*/ | ||
const indented = snippetsNoImports.replace(/^/gm, ' ').trim(); | ||
const formatted = wrapperFnContents | ||
.replace('// %SNIPPET%', indented) | ||
.replace('// %NODE_LAUNCHER%', nodeLauncher); | ||
|
||
/* | ||
Write wrapped snippet to disk | ||
*/ | ||
const wrappedPath = filepath.replace('.ts', '.wrapped.ts'); | ||
const wrappedSnippet = [imports, '\n', formatted].join(''); | ||
|
||
writeFileSync(wrappedPath, wrappedSnippet); | ||
}; | ||
|
||
/* | ||
Wrap all snippets inside `src` dir | ||
*/ | ||
const dir = 'src/**'; | ||
const src = `${dir}/*.ts`; | ||
const ignore = [ | ||
`src/typegend/**`, | ||
`src/env.ts`, | ||
`src/transactions/new-api.ts`, | ||
`${dir}/*.test.ts`, | ||
`${dir}/*.wrapped.ts`, | ||
]; | ||
|
||
globSync(src, { ignore }).forEach(wrapSnippet); |
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,36 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
export const main = async (passLogsThrough: boolean = false): Promise<any | any[]> => { | ||
const logs: any[] = []; | ||
const bkpConsole = console; | ||
|
||
// eslint-disable-next-line no-global-assign | ||
console = { | ||
...console, | ||
log: (...args: any[]) => { | ||
if (passLogsThrough) { | ||
bkpConsole.log.apply(null, args); | ||
} | ||
logs.push(args); | ||
}, | ||
}; | ||
|
||
// TEST NODE LAUNCHER ———>>> | ||
// %NODE_LAUNCHER% | ||
// <<<——— TEST NODE LAUNCHER | ||
|
||
try { | ||
// SNIPPET ———>>> | ||
// %SNIPPET% | ||
// <<<——— SNIPPET | ||
} catch (error) { | ||
console.error(error); | ||
return { error }; | ||
} | ||
|
||
// eslint-disable-next-line no-global-assign | ||
console = bkpConsole; | ||
|
||
return logs; | ||
}; |
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 @@ | ||
export const WALLET_ADDRESS = '<overriden-by-wrapper>'; | ||
export const WALLET_PVT_KEY = '<overriden-by-wrapper>'; | ||
|
||
export const WALLET_ADDRESS_2 = '<overriden-by-wrapper>'; | ||
export const WALLET_PVT_KEY_2 = '<overriden-by-wrapper>'; | ||
|
||
export const WALLET_ADDRESS_3 = '<overriden-by-wrapper>'; | ||
export const WALLET_PVT_KEY_3 = '<overriden-by-wrapper>'; |
9 changes: 9 additions & 0 deletions
9
apps/docs-snippets2/src/introduction/connecting-to-localnode.test.ts
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 @@ | ||
import { main } from './connecting-to-localnode.wrapped'; | ||
|
||
/** | ||
* @group node | ||
*/ | ||
test('it works', async () => { | ||
const [[{ balances }]] = await main(); | ||
expect(balances).toBeInstanceOf(Array); | ||
}); |
12 changes: 12 additions & 0 deletions
12
apps/docs-snippets2/src/introduction/connecting-to-localnode.ts
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,12 @@ | ||
// #region main | ||
nedsalk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { Provider, Wallet, LOCAL_NETWORK_URL } from 'fuels'; | ||
|
||
const ADDRESS = '0x767caf5b08eba21c561078a4d5be09bbd7f16b9eca22699a61f1edd9e456126f'; | ||
|
||
const provider = await Provider.create(LOCAL_NETWORK_URL); | ||
const wallet = Wallet.fromAddress(ADDRESS, provider); | ||
|
||
const { balances } = await wallet.getBalances(); | ||
|
||
console.log({ balances }); | ||
// #endregion main |
9 changes: 9 additions & 0 deletions
9
apps/docs-snippets2/src/introduction/connecting-to-testnet.test.ts
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 @@ | ||
import { main } from './connecting-to-testnet.wrapped'; | ||
|
||
/** | ||
* @group node | ||
*/ | ||
test('it works', async () => { | ||
const [[{ balances }]] = await main(); | ||
expect(balances).toBeInstanceOf(Array); | ||
}); |
12 changes: 12 additions & 0 deletions
12
apps/docs-snippets2/src/introduction/connecting-to-testnet.ts
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,12 @@ | ||
// #region main | ||
import { Provider, Wallet, TESTNET_NETWORK_URL } from 'fuels'; | ||
|
||
const ADDRESS = '0x767caf5b08eba21c561078a4d5be09bbd7f16b9eca22699a61f1edd9e456126f'; | ||
|
||
const provider = await Provider.create(TESTNET_NETWORK_URL); | ||
const wallet = Wallet.fromAddress(ADDRESS, provider); | ||
|
||
const { balances } = await wallet.getBalances(); | ||
|
||
console.log({ balances }); | ||
// #endregion main |
9 changes: 9 additions & 0 deletions
9
apps/docs-snippets2/src/transactions/transaction-parameters.test.ts
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 @@ | ||
import { main } from './transaction-parameters.wrapped'; | ||
|
||
/** | ||
* @group node | ||
*/ | ||
test('it works', async () => { | ||
const [[{ isStatusSuccess }]] = await main(); | ||
expect(isStatusSuccess).toBeTruthy(); | ||
}); |
61 changes: 61 additions & 0 deletions
61
apps/docs-snippets2/src/transactions/transaction-parameters.ts
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,61 @@ | ||
// #region full | ||
import type { TxParams } from 'fuels'; | ||
import { bn, LOCAL_NETWORK_URL, Provider, ScriptTransactionRequest, Wallet } from 'fuels'; | ||
|
||
import { WALLET_PVT_KEY } from '../env'; | ||
import { CounterAbi__factory } from '../typegend'; | ||
import counterBytecode from '../typegend/contracts/CounterAbi.hex'; | ||
import { ScriptSumAbi__factory } from '../typegend/scripts'; | ||
|
||
const { storageSlots } = CounterAbi__factory; | ||
|
||
const provider = await Provider.create(LOCAL_NETWORK_URL); | ||
const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); | ||
|
||
const deploy = await CounterAbi__factory.deployContract(counterBytecode, wallet, { | ||
storageSlots, | ||
}); | ||
|
||
const { contract } = await deploy.waitForResult(); | ||
|
||
// #region transaction-parameters-6 | ||
const txParams: TxParams = { | ||
// #region transaction-parameters-1 | ||
gasLimit: bn(69242), | ||
// #endregion transaction-parameters-1 | ||
// #region transaction-parameters-2 | ||
maxFee: bn(69242), | ||
// #endregion transaction-parameters-2 | ||
// #region transaction-parameters-3 | ||
tip: bn(100), | ||
// #endregion transaction-parameters-3 | ||
// #region transaction-parameters-4 | ||
maturity: 1, | ||
// #endregion transaction-parameters-4 | ||
// #region transaction-parameters-5 | ||
witnessLimit: bn(5000), | ||
// #endregion transaction-parameters-5 | ||
}; | ||
// #endregion transaction-parameters-6 | ||
|
||
// #region transaction-parameters-7 | ||
const transactionRequest = new ScriptTransactionRequest({ | ||
script: ScriptSumAbi__factory.bin, | ||
gasLimit: 100, | ||
}); | ||
// #endregion transaction-parameters-7 | ||
|
||
// #region transaction-parameters-8 | ||
const { waitForResult } = await contract.functions | ||
.increment_count(15) // | ||
.txParams(txParams) | ||
.call(); | ||
|
||
const { | ||
value, | ||
transactionResult: { isStatusSuccess }, | ||
} = await waitForResult(); | ||
|
||
console.log({ value, isStatusSuccess, transactionRequest }); | ||
// #endregion transaction-parameters-8 | ||
// #endregion full |
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,2 @@ | ||
[workspace] | ||
members = ["counter", "script-sum"] |
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,7 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "counter" | ||
|
||
[dependencies] |
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 Counter { | ||
#[storage(read)] | ||
fn get_count() -> u64; | ||
|
||
#[storage(write, read)] | ||
fn increment_count(amount: u64) -> u64; | ||
} | ||
|
||
storage { | ||
counter: u64 = 0, | ||
} | ||
|
||
impl Counter for Contract { | ||
#[storage(read)] | ||
fn get_count() -> u64 { | ||
storage.counter.read() | ||
} | ||
|
||
#[storage(write, read)] | ||
fn increment_count(amount: u64) -> u64 { | ||
let current = storage.counter.read(); | ||
storage.counter.write(current + amount); | ||
storage.counter.read() | ||
} | ||
} |
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,7 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "script-sum" | ||
|
||
[dependencies] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we prefix the
docs-snippets
with@fuel-ts/
? I thought we only did this for packages?