Skip to content
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

chore: remove sway-libs dep from testing fixtures #2189

Merged
merged 20 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/docs-snippets/src/guide/types/vector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ describe(__filename, () => {
// #import { arrayify, readFile };

const bytecode = await readFile(bytecodePath);
const bytecodeAsVecU8 = arrayify(bytecode);

const { value: bytecodeRoot } = await bytecodeContract.functions
.compute_bytecode_root(arrayify(bytecode))
.compute_bytecode_root(Array.from(bytecodeAsVecU8))
maschad marked this conversation as resolved.
Show resolved Hide resolved
.call();
// #endregion vector-bytecode-input-ts

console.log('bytecodeRoot:', bytecodeRoot);
maschad marked this conversation as resolved.
Show resolved Hide resolved
expect(bytecodeRoot).toBeDefined();
expect(bytecodeRoot.length).toBe(66);
});
Expand Down
23 changes: 2 additions & 21 deletions apps/docs/src/guide/types/vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,9 @@ The code snippet below demonstrates how to call this Sway contract method, which

<<< @/../../docs-snippets/src/guide/types/vector.test.ts#vector-4{ts:line-numbers}

## Working with Bytecode in the SDK
## Converting Bytecode to Vec<u8>

Some Sway functions require you to pass in bytecode to the function. The type of the bytecode parameter is usually `Vec<u8>`.

Take the `compute_bytecode_root` function from the [`bytecode` Sway library](https://github.com/FuelLabs/sway-libs/tree/master/libs/src/bytecode.sw), for example.

<<< @/../../docs-snippets/test/fixtures/forc-projects/bytecode-input/src/main.sw#vector-bytecode-input-sway{ts:line-numbers}
maschad marked this conversation as resolved.
Show resolved Hide resolved

```rust
contract;

abi MyContract {
fn compute_bytecode_root(bytecode_input: Vec<u8>) -> b256;
}

impl MyContract for Contract {
fn compute_bytecode_root(bytecode_input: Vec<u8>) -> b256 {
let root = compute_bytecode_root(bytecode_input);
return root;
}
}
```
Some Sway functions require you to pass in bytecode to the function. The type of the bytecode parameter is usually Vec<u8>. For example, take the compute_bytecode_root function from the [bytecode Sway library](https://fuellabs.github.io/sway-libs/book/bytecode/index.html?highlight=bytecode#using-the-bytecode-library-in-sway).

To pass bytecode to this function, you can make use of the `arrayify` function to convert the bytecode file contents into a `UInt8Array`, the TS compatible type for Sway's `Vec<u8>` type and pass it the function like so:

Expand Down
Loading