-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c912c6
commit b8c3401
Showing
12 changed files
with
283 additions
and
182 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@fuel-ts/program": patch | ||
--- | ||
|
||
implement `get` method on `BaseInvocationScope` |
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
65 changes: 65 additions & 0 deletions
65
apps/docs-snippets/src/guide/contracts/interacting-with-contracts.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,65 @@ | ||
import type { Provider } from 'fuels'; | ||
import { BaseAssetId, Contract } from 'fuels'; | ||
|
||
import { DocSnippetProjectsEnum } from '../../../test/fixtures/forc-projects'; | ||
import { createAndDeployContractFromProject, getTestWallet } from '../../utils'; | ||
|
||
/** | ||
* @group node | ||
*/ | ||
describe(__filename, () => { | ||
let counterContract: Contract; | ||
let provider: Provider; | ||
beforeAll(async () => { | ||
counterContract = await createAndDeployContractFromProject(DocSnippetProjectsEnum.COUNTER); | ||
provider = counterContract.provider; | ||
}); | ||
|
||
it('should successfully use "get" to read from the blockchain', async () => { | ||
await counterContract.functions.increment_count(1).call(); | ||
|
||
const { id: contractId, interface: abi } = counterContract; | ||
|
||
// #region interacting-with-contracts-1 | ||
const contract = new Contract(contractId, abi, provider); | ||
|
||
const { value } = await contract.functions.get_count().get(); | ||
// #endregion interacting-with-contracts-1 | ||
expect(value.toNumber()).toBeGreaterThanOrEqual(1); | ||
}); | ||
|
||
it('should successfully use "dryRun" to validate a TX without a wallet', async () => { | ||
const { id: contractId, interface: abi } = counterContract; | ||
|
||
// #region interacting-with-contracts-2 | ||
const contract = new Contract(contractId, abi, provider); | ||
|
||
const { value } = await contract.functions.increment_count(1).dryRun(); | ||
// #endregion interacting-with-contracts-2 | ||
expect(value.toNumber()).toBeGreaterThanOrEqual(1); | ||
}); | ||
|
||
it('should successfully use "simulate" to validate if wallet can pay for transaction', async () => { | ||
const { id: contractId, interface: abi } = counterContract; | ||
|
||
const fundedWallet = await getTestWallet([[1000, BaseAssetId]]); | ||
|
||
// #region interacting-with-contracts-3 | ||
const contract = new Contract(contractId, abi, fundedWallet); | ||
|
||
const { value } = await contract.functions.increment_count(10).simulate(); | ||
// #endregion interacting-with-contracts-3 | ||
expect(value.toNumber()).toBeGreaterThanOrEqual(10); | ||
}); | ||
|
||
it('should successfully execute a contract call without a wallet', async () => { | ||
const contract = counterContract; | ||
|
||
// #region interacting-with-contracts-4 | ||
await contract.functions.increment_count(10).call(); | ||
// #endregion interacting-with-contracts-4 | ||
|
||
const { value } = await contract.functions.get_count().get(); | ||
expect(value.toNumber()).toBeGreaterThanOrEqual(10); | ||
}); | ||
}); |
76 changes: 0 additions & 76 deletions
76
apps/docs-snippets/src/guide/contracts/simulate-transactions.test.ts
This file was deleted.
Oops, something went wrong.
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
31 changes: 31 additions & 0 deletions
31
apps/docs/src/guide/contracts/interacting-with-contracts.md
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 @@ | ||
# Interacting With Contracts | ||
|
||
There are 4 ways to interact with contracts: `get`, `dryRun`, `simulate`, `call`. | ||
|
||
## `get` | ||
|
||
The `get` method should be used to read data from the blockchain without using resources. It can be used with an unfunded wallet or even without a wallet at all: | ||
|
||
<<< @/../../docs-snippets/src/guide/contracts/interacting-with-contracts.test.ts#interacting-with-contracts-1{ts:line-numbers} | ||
|
||
## `dryRun` | ||
|
||
The `dryRun` method should be used to dry-run a contract call. It does not spend resources and can be used with an unfunded wallet or even without a wallet at all: | ||
|
||
<<< @/../../docs-snippets/src/guide/contracts/interacting-with-contracts.test.ts#interacting-with-contracts-2{ts:line-numbers} | ||
|
||
## `simulate` | ||
|
||
The `simulate` method should be used to dry-run a contract call, ensuring that the wallet used has sufficient funds to cover the transaction fees, without consuming any resources. | ||
|
||
A funded wallet it's required: | ||
|
||
<<< @/../../docs-snippets/src/guide/contracts/interacting-with-contracts.test.ts#interacting-with-contracts-3{ts:line-numbers} | ||
|
||
## `call` | ||
|
||
The `call` method should be used to submit a real contract call transaction to the node. | ||
|
||
Real resources are consumed, and any operations executed by the contract function will be processed on the blockchain. | ||
|
||
<<< @/../../docs-snippets/src/guide/contracts/interacting-with-contracts.test.ts#interacting-with-contracts-4{ts:line-numbers} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.