From 3e03409b5155226b11f7b6728f81af09475afefb Mon Sep 17 00:00:00 2001 From: Cameron Manavian Date: Fri, 20 Oct 2023 03:36:33 -0700 Subject: [PATCH] feat: update forc to `v0.46.1` (#1343) * up v * add cs * format * cleanup sway files as part of upgrade * update * add AssetId * update abi * add * add tests * update check * adjust * adjust logs * add * catch invalid string types * fixes * update * change encoded length value * lint --- .changeset/lovely-buttons-sparkle.md | 5 + .vscode/settings.json | 5 +- .../projects/echo-configurables/src/main.sw | 2 +- .../projects/return-context/src/main.sw | 2 +- .../projects/simple-token/src/main.sw | 5 +- packages/abi-coder/src/abi-coder.ts | 10 ++ .../abi-coder/src/coders/asset-id.test.ts | 94 +++++++++++++++++++ packages/abi-coder/src/coders/asset-id.ts | 36 +++++++ packages/abi-coder/src/coders/stdString.ts | 2 +- .../exhaustive-examples/src/main.sw | 7 +- .../src/abi/types/AssetIdType.test.ts | 27 ++++++ .../abi-typegen/src/abi/types/AssetIdType.ts | 13 +++ .../fixtures/forc-projects/full/src/main.sw | 11 ++- .../test/fixtures/templates/contract/dts.hbs | 10 ++ .../predicate-with-configurable/factory.hbs | 4 +- packages/errors/src/error-codes.ts | 1 + packages/forc/VERSION | 2 +- .../fixtures/forc-projects/Forc.toml | 2 +- .../src/main.sw | 4 +- .../advanced-logging/src/main.sw | 18 ++-- .../call-test-contract/src/main.sw | 2 +- .../configurable-contract/src/main.sw | 6 +- .../coverage-contract/src/main.sw | 10 +- .../forc-projects/liquidity-pool/src/main.sw | 8 +- .../predicate-conditional-inputs/src/main.sw | 8 +- .../forc-projects/revert-error/src/main.sw | 14 ++- .../script-main-args/src/main.sw | 2 +- .../script-main-two-args/src/main.sw | 6 +- .../script-with-vector/src/main.sw | 8 +- .../vector-types-contract/src/main.sw | 22 ++--- .../vector-types-script/src/main.sw | 22 ++--- packages/fuel-gauge/src/raw-slice.test.ts | 3 +- .../src/script-with-vectors.test.ts | 4 +- .../versions/src/lib/getSupportedVersions.ts | 2 +- 34 files changed, 297 insertions(+), 80 deletions(-) create mode 100644 .changeset/lovely-buttons-sparkle.md create mode 100644 packages/abi-coder/src/coders/asset-id.test.ts create mode 100644 packages/abi-coder/src/coders/asset-id.ts create mode 100644 packages/abi-typegen/src/abi/types/AssetIdType.test.ts create mode 100644 packages/abi-typegen/src/abi/types/AssetIdType.ts diff --git a/.changeset/lovely-buttons-sparkle.md b/.changeset/lovely-buttons-sparkle.md new file mode 100644 index 00000000000..e622d74d1ec --- /dev/null +++ b/.changeset/lovely-buttons-sparkle.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/forc": minor +--- + +Updated forc version diff --git a/.vscode/settings.json b/.vscode/settings.json index ef6425c6fce..9265bce8080 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,5 +23,8 @@ "editor.formatOnSave": false, "editor.formatOnPaste": false }, - "typescript.tsdk": "node_modules/typescript/lib" + "typescript.tsdk": "node_modules/typescript/lib", + "[sway]": { + "editor.defaultFormatter": "FuelLabs.sway-vscode-plugin" + } } diff --git a/apps/docs-snippets/projects/echo-configurables/src/main.sw b/apps/docs-snippets/projects/echo-configurables/src/main.sw index 1159e8a7123..d4f583f14d5 100644 --- a/apps/docs-snippets/projects/echo-configurables/src/main.sw +++ b/apps/docs-snippets/projects/echo-configurables/src/main.sw @@ -14,7 +14,7 @@ struct MyStruct { configurable { age: u8 = 25, - tag: str[4] = "fuel", + tag: str[4] = __to_str_array("fuel"), grades: [u8; 4] = [3, 4, 3, 2], my_struct: MyStruct = MyStruct { x: 1, diff --git a/apps/docs-snippets/projects/return-context/src/main.sw b/apps/docs-snippets/projects/return-context/src/main.sw index b379a2dda0c..c07aa079c67 100644 --- a/apps/docs-snippets/projects/return-context/src/main.sw +++ b/apps/docs-snippets/projects/return-context/src/main.sw @@ -1,6 +1,6 @@ contract; -use std::{context::{msg_amount}}; +use std::context::msg_amount; abi ReturnContext { #[payable] diff --git a/apps/docs-snippets/projects/simple-token/src/main.sw b/apps/docs-snippets/projects/simple-token/src/main.sw index e22a8b53a8c..b77372198b2 100644 --- a/apps/docs-snippets/projects/simple-token/src/main.sw +++ b/apps/docs-snippets/projects/simple-token/src/main.sw @@ -3,22 +3,19 @@ contract; use ::simple_token_abi::SimpleToken; +use std::hash::*; storage { balances: StorageMap = StorageMap {}, } - impl SimpleToken for Contract { #[storage(read, write)] fn deposit(address: b256, amount: u64) { let current_balance = storage.balances.get(address).try_read().unwrap_or(0); - storage.balances.insert(address, current_balance + amount); } - #[storage(read)] fn get_balance(address: b256) -> u64 { let balance = storage.balances.get(address).try_read().unwrap_or(0); - balance } } diff --git a/packages/abi-coder/src/abi-coder.ts b/packages/abi-coder/src/abi-coder.ts index 397687b2711..f62240ce275 100644 --- a/packages/abi-coder/src/abi-coder.ts +++ b/packages/abi-coder/src/abi-coder.ts @@ -3,6 +3,7 @@ import { ErrorCode, FuelError } from '@fuel-ts/errors'; import type { DecodedValue, InputValue, Coder } from './coders/abstract-coder'; import { ArrayCoder } from './coders/array'; +import { AssetIdCoder } from './coders/asset-id'; import { B256Coder } from './coders/b256'; import { B512Coder } from './coders/b512'; import { BooleanCoder } from './coders/boolean'; @@ -69,6 +70,8 @@ export abstract class AbiCoder { return new B256Coder(); case 'struct B512': return new B512Coder(); + case 'struct AssetId': + return new AssetIdCoder(); case BYTES_CODER_TYPE: return new ByteCoder(); case STD_STRING_CODER_TYPE: @@ -140,6 +143,13 @@ export abstract class AbiCoder { return new TupleCoder(coders); } + if (resolvedAbiType.type === 'str') { + throw new FuelError( + ErrorCode.INVALID_DATA, + 'String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`' + ); + } + throw new FuelError( ErrorCode.CODER_NOT_FOUND, `Coder not found: ${JSON.stringify(resolvedAbiType)}.` diff --git a/packages/abi-coder/src/coders/asset-id.test.ts b/packages/abi-coder/src/coders/asset-id.test.ts new file mode 100644 index 00000000000..388165eebd2 --- /dev/null +++ b/packages/abi-coder/src/coders/asset-id.test.ts @@ -0,0 +1,94 @@ +import { AssetIdCoder } from './asset-id'; + +describe('AssetIdCoder', () => { + const B256_DECODED = '0xd5579c46dfcc7f18207013e65b44e4cb4e2c2298f4ac457ba8f82743f31e930b'; + const B256_ENCODED = new Uint8Array([ + 213, 87, 156, 70, 223, 204, 127, 24, 32, 112, 19, 230, 91, 68, 228, 203, 78, 44, 34, 152, 244, + 172, 69, 123, 168, 248, 39, 67, 243, 30, 147, 11, + ]); + const B256_ZERO_DECODED = '0x0000000000000000000000000000000000000000000000000000000000000000'; + const B256_ZERO_ENCODED = new Uint8Array(32); + + const coder = new AssetIdCoder(); + + it('should encode zero as a 256 bit hash string', () => { + const expected = B256_ZERO_ENCODED; + const actual = coder.encode(B256_ZERO_DECODED); + + expect(actual).toStrictEqual(expected); + }); + + it('should encode a 256 bit hash string', () => { + const expected = B256_ENCODED; + const actual = coder.encode(B256_DECODED); + + expect(actual).toStrictEqual(expected); + }); + + it('should decode zero as a 256 bit hash string', () => { + const expectedValue = B256_ZERO_DECODED; + const expectedLength = B256_ZERO_ENCODED.length; + const [actualValue, actualLength] = coder.decode(B256_ZERO_ENCODED, 0); + + expect(actualValue).toStrictEqual(expectedValue); + expect(actualLength).toBe(expectedLength); + }); + + it('should decode a 256 bit hash string', () => { + const expectedValue = B256_DECODED; + const expectedLength = B256_ENCODED.length; + const [actualValue, actualLength] = coder.decode(B256_ENCODED, 0); + + expect(actualValue).toStrictEqual(expectedValue); + expect(actualLength).toBe(expectedLength); + }); + + it('should throw an error when encoding a 256 bit hash string that is too short', () => { + const invalidInput = B256_DECODED.slice(0, B256_DECODED.length - 1); + + expect(() => { + coder.encode(invalidInput); + }).toThrow('Invalid struct AssetId'); + }); + + it('should throw an error when decoding an encoded 256 bit hash string that is too short', () => { + const invalidInput = B256_ENCODED.slice(0, B256_ENCODED.length - 1); + + expect(() => { + coder.decode(invalidInput, 0); + }).toThrow(); + }); + + it('should throw an error when encoding a 256 bit hash string that is too long', () => { + const invalidInput = `${B256_DECODED}0`; + + expect(() => { + coder.encode(invalidInput); + }).toThrow('Invalid struct AssetId'); + }); + + it('should throw an error when encoding a 512 bit hash string', () => { + const B512 = + '0x8e9dda6f7793745ac5aacf9e907cae30b2a01fdf0d23b7750a85c6a44fca0c29f0906f9d1f1e92e6a1fb3c3dcef3cc3b3cdbaae27e47b9d9a4c6a4fce4cf16b2'; + + expect(() => { + coder.encode(B512); + }).toThrow('Invalid struct AssetId'); + }); + + it('should throw an error when decoding an encoded 256 bit hash string that is too long', () => { + const invalidInput = new Uint8Array(Array.from(Array(32).keys())); + + expect(() => { + coder.decode(invalidInput, 1); + }).toThrow('Invalid size for AssetId'); + }); + + it('should throw an error when encoding a 256 bit hash string that is not a hex string', () => { + const invalidInput = 'not a hex string'; + + expect(() => { + coder.encode(invalidInput); + }).toThrow('Invalid struct AssetId'); + }); +}); diff --git a/packages/abi-coder/src/coders/asset-id.ts b/packages/abi-coder/src/coders/asset-id.ts new file mode 100644 index 00000000000..e1b3d65d9e4 --- /dev/null +++ b/packages/abi-coder/src/coders/asset-id.ts @@ -0,0 +1,36 @@ +import { ErrorCode } from '@fuel-ts/errors'; +import { bn, toHex } from '@fuel-ts/math'; +import { getBytes } from 'ethers'; + +import { Coder } from './abstract-coder'; + +export class AssetIdCoder extends Coder { + constructor() { + super('AssetId', 'struct AssetId', 32); + } + + encode(value: string): Uint8Array { + let encodedValue; + try { + encodedValue = getBytes(value); + } catch (error) { + this.throwError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`); + } + if (encodedValue.length !== 32) { + this.throwError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`); + } + return encodedValue; + } + + decode(data: Uint8Array, offset: number): [string, number] { + let bytes = data.slice(offset, offset + 32); + const decoded = bn(bytes); + if (decoded.isZero()) { + bytes = new Uint8Array(32); + } + if (bytes.length !== 32) { + this.throwError(ErrorCode.DECODE_ERROR, `Invalid size for AssetId.`); + } + return [toHex(bytes, 32), offset + 32]; + } +} diff --git a/packages/abi-coder/src/coders/stdString.ts b/packages/abi-coder/src/coders/stdString.ts index 599d7cf739d..756be1eb946 100644 --- a/packages/abi-coder/src/coders/stdString.ts +++ b/packages/abi-coder/src/coders/stdString.ts @@ -12,7 +12,7 @@ import { U64Coder } from './u64'; export class StdStringCoder extends Coder { static memorySize = 1; constructor() { - super('struct', 'struct String', BASE_VECTOR_OFFSET); + super('struct', 'struct String', 1); } encode(value: string): Uint8Array { diff --git a/packages/abi-coder/test/sway-projects/exhaustive-examples/src/main.sw b/packages/abi-coder/test/sway-projects/exhaustive-examples/src/main.sw index bd532142afd..b8f5cff0996 100644 --- a/packages/abi-coder/test/sway-projects/exhaustive-examples/src/main.sw +++ b/packages/abi-coder/test/sway-projects/exhaustive-examples/src/main.sw @@ -12,7 +12,7 @@ configurable { U8: u8 = 8u8, BOOL: bool = true, ARRAY: [u32; 3] = [253u32, 254u32, 255u32], - STR_4: str[4] = "fuel", + STR_4: str[4] = __to_str_array("fuel"), STRUCT: StructA = StructA { propA1: 8u8, propA2: true, @@ -137,6 +137,7 @@ abi MyContract { fn bytes(arg: Bytes) -> Bytes; fn raw_slice(arg: raw_slice) -> raw_slice; fn dynamic_string(arg: String) -> String; + fn asset_id(arg: AssetId) -> AssetId; fn tuple_as_param(x: (u8, StructA, str[3]>)) -> (u8, StructA, str[3]>); fn array_simple(x: [u8; 4]) -> [u8; 4]; @@ -260,6 +261,10 @@ impl MyContract for Contract { arg } + fn asset_id(arg: AssetId) -> AssetId { + arg + } + fn two_u8_vectors(x: Vec, y: Vec) -> (Vec, Vec) { (x, y) } diff --git a/packages/abi-typegen/src/abi/types/AssetIdType.test.ts b/packages/abi-typegen/src/abi/types/AssetIdType.test.ts new file mode 100644 index 00000000000..cbfe43ac48b --- /dev/null +++ b/packages/abi-typegen/src/abi/types/AssetIdType.test.ts @@ -0,0 +1,27 @@ +import { AssetIdType } from './AssetIdType'; +import { BoolType } from './BoolType'; + +describe('AssetIdType.ts', () => { + test('should properly parse type attributes', () => { + const b512 = new AssetIdType({ + rawAbiType: { + components: null, + typeParameters: null, + typeId: 1, + type: AssetIdType.swayType, + }, + }); + + b512.parseComponentsAttributes({ types: [] }); + + const suitableForAssetId = AssetIdType.isSuitableFor({ type: AssetIdType.swayType }); + const suitableForBool = AssetIdType.isSuitableFor({ type: BoolType.swayType }); + + expect(suitableForAssetId).toEqual(true); + expect(suitableForBool).toEqual(false); + + expect(b512.attributes.inputLabel).toEqual('string'); + expect(b512.attributes.outputLabel).toEqual('string'); + expect(b512.requiredFuelsMembersImports).toStrictEqual([]); + }); +}); diff --git a/packages/abi-typegen/src/abi/types/AssetIdType.ts b/packages/abi-typegen/src/abi/types/AssetIdType.ts new file mode 100644 index 00000000000..04f1d52635c --- /dev/null +++ b/packages/abi-typegen/src/abi/types/AssetIdType.ts @@ -0,0 +1,13 @@ +import { B256Type } from './B256Type'; + +export class AssetIdType extends B256Type { + public static swayType = 'struct AssetId'; + + public name = 'AssetId'; + + static MATCH_REGEX = /^struct AssetId$/m; + + static isSuitableFor(params: { type: string }) { + return AssetIdType.MATCH_REGEX.test(params.type); + } +} diff --git a/packages/abi-typegen/test/fixtures/forc-projects/full/src/main.sw b/packages/abi-typegen/test/fixtures/forc-projects/full/src/main.sw index ad239b8449e..3499e5d942a 100644 --- a/packages/abi-typegen/test/fixtures/forc-projects/full/src/main.sw +++ b/packages/abi-typegen/test/fixtures/forc-projects/full/src/main.sw @@ -1,6 +1,7 @@ contract; use std::vm::evm::evm_address::EvmAddress; +use std::b512::B512; use std::string::String; use std::bytes::Bytes; @@ -29,8 +30,10 @@ abi MyContract { fn types_u32(x: u32) -> u32; fn types_u64(x: u64) -> u64; fn types_str(x: str[5]) -> str[5]; + fn types_asset_id(x: AssetId) -> AssetId; fn types_bool(x: bool) -> bool; fn types_b256(x: b256) -> b256; + fn types_b512(x: B512) -> B512; fn types_struct(x: MyStruct) -> MyStruct; fn types_array(x: [u8; 3]) -> [u8; 3]; fn types_tuple(x: (u8, u8, u8)) -> (u8, u8, u8); @@ -60,14 +63,20 @@ impl MyContract for Contract { 4294967295000 } fn types_str(x: str[5]) -> str[5] { - "Hello" + __to_str_array("Hello") } fn types_bool(x: bool) -> bool { true } + fn types_asset_id(x: AssetId) -> AssetId { + x + } fn types_b256(x: b256) -> b256 { 0x0000000000000000000000000000000000000000000000000000000000000000 } + fn types_b512(x: B512) -> B512 { + x + } fn types_array(x: [u8; 3]) -> [u8; 3] { x } diff --git a/packages/abi-typegen/test/fixtures/templates/contract/dts.hbs b/packages/abi-typegen/test/fixtures/templates/contract/dts.hbs index f6b2b4ab677..7c4f05404db 100644 --- a/packages/abi-typegen/test/fixtures/templates/contract/dts.hbs +++ b/packages/abi-typegen/test/fixtures/templates/contract/dts.hbs @@ -26,6 +26,8 @@ import type { Option, Enum, Vec } from "./common"; export enum MyEnumInput { Checked = 'Checked', Pending = 'Pending' }; export enum MyEnumOutput { Checked = 'Checked', Pending = 'Pending' }; +export type AssetIdInput = { value: string }; +export type AssetIdOutput = AssetIdInput; export type MyStructInput = { x: BigNumberish, y: BigNumberish, state: MyEnumInput }; export type MyStructOutput = { x: number, y: number, state: MyEnumOutput }; export type RawBytesInput = { ptr: BigNumberish, cap: BigNumberish }; @@ -36,7 +38,9 @@ export type StructWithMultiOptionOutput = { multiple: [Option, Option]): Uint8Array; decodeFunctionData(functionFragment: 'types_array', data: BytesLike): DecodedValue; + decodeFunctionData(functionFragment: 'types_asset_id', data: BytesLike): DecodedValue; decodeFunctionData(functionFragment: 'types_b256', data: BytesLike): DecodedValue; + decodeFunctionData(functionFragment: 'types_b512', data: BytesLike): DecodedValue; decodeFunctionData(functionFragment: 'types_bool', data: BytesLike): DecodedValue; decodeFunctionData(functionFragment: 'types_bytes', data: BytesLike): DecodedValue; decodeFunctionData(functionFragment: 'types_enum', data: BytesLike): DecodedValue; @@ -104,7 +112,9 @@ export class MyContractAbi extends Contract { interface: MyContractAbiInterface; functions: { types_array: InvokeFunction<[x: [BigNumberish, BigNumberish, BigNumberish]], [number, number, number]>; + types_asset_id: InvokeFunction<[x: AssetIdInput], AssetIdOutput>; types_b256: InvokeFunction<[x: string], string>; + types_b512: InvokeFunction<[x: string], string>; types_bool: InvokeFunction<[x: boolean], boolean>; types_bytes: InvokeFunction<[x: Bytes], Bytes>; types_enum: InvokeFunction<[x: MyEnumInput], MyEnumOutput>; diff --git a/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/factory.hbs b/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/factory.hbs index bab0b423b84..98833c493f4 100644 --- a/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/factory.hbs +++ b/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/factory.hbs @@ -76,7 +76,7 @@ const _abi = { "type": 2, "typeArguments": null }, - "offset": 152 + "offset": 128 }, { "name": "ADDRESS", @@ -85,7 +85,7 @@ const _abi = { "type": 0, "typeArguments": null }, - "offset": 160 + "offset": 136 } ] } diff --git a/packages/errors/src/error-codes.ts b/packages/errors/src/error-codes.ts index 8d574b2aaef..ea1f15106ee 100644 --- a/packages/errors/src/error-codes.ts +++ b/packages/errors/src/error-codes.ts @@ -15,6 +15,7 @@ export enum ErrorCode { TYPE_ID_NOT_FOUND = 'type-id-not-found', BIN_FILE_NOT_FOUND = 'bin-file-not-found', CODER_NOT_FOUND = 'coder-not-found', + INVALID_DATA = 'invalid-data', FUNCTION_NOT_FOUND = 'function-not-found', // address diff --git a/packages/forc/VERSION b/packages/forc/VERSION index a8ab6c9666a..620104d8208 100644 --- a/packages/forc/VERSION +++ b/packages/forc/VERSION @@ -1 +1 @@ -0.44.0 +0.46.1 diff --git a/packages/fuel-gauge/fixtures/forc-projects/Forc.toml b/packages/fuel-gauge/fixtures/forc-projects/Forc.toml index 4cbb241bbdd..5c18c8cac81 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/Forc.toml +++ b/packages/fuel-gauge/fixtures/forc-projects/Forc.toml @@ -35,7 +35,7 @@ members = [ "script-main-args", "script-main-return-struct", "script-main-two-args", - "script-raw-slice", + # "script-raw-slice", see https://github.com/FuelLabs/fuels-ts/issues/1344 "script-std-lib-string", "script-with-configurable", "script-with-array", diff --git a/packages/fuel-gauge/fixtures/forc-projects/advanced-logging-other-contract/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/advanced-logging-other-contract/src/main.sw index 7795844f159..af037fed599 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/advanced-logging-other-contract/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/advanced-logging-other-contract/src/main.sw @@ -6,8 +6,8 @@ use advanced_logging_other_contract_abi::AdvancedLoggingOtherContract; impl AdvancedLoggingOtherContract for Contract { fn msg_from_other_contract(a: u8) { - log("Hello from other Contract"); - log("Received value from main Contract:"); + log(__to_str_array("Hello from other Contract")); + log(__to_str_array("Received value from main Contract:")); log(a); } } diff --git a/packages/fuel-gauge/fixtures/forc-projects/advanced-logging/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/advanced-logging/src/main.sw index bd74a75d67e..cbba7e2a8f2 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/advanced-logging/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/advanced-logging/src/main.sw @@ -49,19 +49,19 @@ impl AdvancedLogging for Contract { difficulty: Difficulty::Medium(true), }; - log("Game State"); + log(__to_str_array("Game State")); log(state); - log("Contract Id"); + log(__to_str_array("Contract Id")); log(contract_id); - log("Game Ref"); + log(__to_str_array("Game Ref")); log(game_ref); - log("Game Ref Score"); + log(__to_str_array("Game Ref Score")); log(game_ref.score); - log("Direct Game"); + log(__to_str_array("Direct Game")); log(Game { score: 101, time_left: 12, @@ -73,11 +73,11 @@ impl AdvancedLogging for Contract { }); if 1 == 1 { - log("Was True"); + log(__to_str_array("Was True")); } if 1 == 2 { - log("The Sky is falling"); + log(__to_str_array("The Sky is falling")); } true @@ -98,7 +98,7 @@ impl AdvancedLogging for Contract { }; require(a == b, game_ref); - log("Hello Tester"); + log(__to_str_array("Hello Tester")); log(state); true @@ -106,7 +106,7 @@ impl AdvancedLogging for Contract { fn test_log_from_other_contract(a: u8, contract_id: b256) -> bool { let other_contract = abi(AdvancedLoggingOtherContract, contract_id); - log("Hello from main Contract"); + log(__to_str_array("Hello from main Contract")); other_contract.msg_from_other_contract(a); true } diff --git a/packages/fuel-gauge/fixtures/forc-projects/call-test-contract/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/call-test-contract/src/main.sw index 1bf2e4f1a3c..b3878aa19bf 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/call-test-contract/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/call-test-contract/src/main.sw @@ -127,7 +127,7 @@ impl TestContract for Contract { #[payable] fn return_context_asset() -> b256 { - msg_asset_id() + msg_asset_id().value } #[payable] diff --git a/packages/fuel-gauge/fixtures/forc-projects/configurable-contract/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/configurable-contract/src/main.sw index 6da912372b0..02dac8d6d31 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/configurable-contract/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/configurable-contract/src/main.sw @@ -20,10 +20,10 @@ configurable { B256: b256 = 0x1d6ebd57dd6a8d7e90889c8c7388f22c30d5c3556080a2b6dc4c521092a0b942, ENUM: Colors = Colors::red, ARRAY: [[u32; 2]; 2] = [[253u32, 254u32], [255u32, 256u32]], - STR_4: str[4] = "fuel", - TUPLE: (u8, bool, str[2]) = (12, false, "hi"), + STR_4: str[4] = __to_str_array("fuel"), + TUPLE: (u8, bool, str[2]) = (12, false, __to_str_array("hi")), STRUCT_1: Struct1 = Struct1 { - tag: "000", + tag: __to_str_array("000"), age: 21, scores: [1, 3, 4], }, diff --git a/packages/fuel-gauge/fixtures/forc-projects/coverage-contract/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/coverage-contract/src/main.sw index 85def96429c..976acb7db41 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/coverage-contract/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/coverage-contract/src/main.sw @@ -160,7 +160,7 @@ impl CoverageContract for Contract { fn produce_logs_variables() -> () { let f: u64 = 64; let u: b256 = 0xef86afa9696cf0dc6385e2c407a6e159a1103cefb7e2ae0636fb33d3cb2a9e4a; - let e: str[4] = "Fuel"; + let e: str[4] = __to_str_array("Fuel"); let l: [u8; 3] = [1u8, 2u8, 3u8]; log(f); @@ -174,12 +174,12 @@ impl CoverageContract for Contract { } fn get_small_string() -> str[8] { - let my_string: str[8] = "gggggggg"; + let my_string: str[8] = __to_str_array("gggggggg"); my_string } fn get_large_string() -> str[9] { - let my_string: str[9] = "ggggggggg"; + let my_string: str[9] = __to_str_array("ggggggggg"); my_string } @@ -225,13 +225,13 @@ impl CoverageContract for Contract { assert(length == 5); assert(vector.capacity() == 5); assert(vector.is_empty() == false); - log("vector.items"); + log(__to_str_array("vector.items")); log(vector.get(0)); log(vector.get(1)); log(vector.get(2)); log(vector.get(3)); log(vector.get(4)); - log("vector.len"); + log(__to_str_array("vector.len")); log(vector.len); true }, diff --git a/packages/fuel-gauge/fixtures/forc-projects/liquidity-pool/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/liquidity-pool/src/main.sw index 685d6d8754c..d2faaf4eaf0 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/liquidity-pool/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/liquidity-pool/src/main.sw @@ -27,13 +27,17 @@ abi LiquidityPool { } storage { - base_token: b256 = 0x0000000000000000000000000000000000000000000000000000000000000000, + base_token: AssetId = AssetId { + value: 0x0000000000000000000000000000000000000000000000000000000000000000, + }, } impl LiquidityPool for Contract { #[storage(write)] fn set_base_token(base_token_id: b256) { - storage.base_token.write(base_token_id); + storage.base_token.write(AssetId { + value: base_token_id, + }); } #[storage(read), payable] diff --git a/packages/fuel-gauge/fixtures/forc-projects/predicate-conditional-inputs/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/predicate-conditional-inputs/src/main.sw index ed44e6fd9c3..f1121c9a6b8 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/predicate-conditional-inputs/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/predicate-conditional-inputs/src/main.sw @@ -1,13 +1,10 @@ predicate; -use std::inputs::{input_owner}; -use std::constants::{ZERO_B256}; - +use std::inputs::input_owner; +use std::constants::ZERO_B256; configurable { - /// Order owner MAKER: b256 = ZERO_B256, } - fn main() -> bool { if (input_owner(0).unwrap() == Address::from(MAKER) || input_owner(1).unwrap() == Address::from(MAKER) @@ -15,6 +12,5 @@ fn main() -> bool { { return true; } - false } diff --git a/packages/fuel-gauge/fixtures/forc-projects/revert-error/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/revert-error/src/main.sw index 4ab53977f5b..f808341b8cb 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/revert-error/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/revert-error/src/main.sw @@ -20,6 +20,14 @@ abi RevertError { fn failed_transfer_revert(); } +const BASE_TOKEN_A: AssetId = AssetId { + value: 0x0000000000000000000000000000000000000000000000000000000000000001, +}; + +const BASE_TOKEN_B: AssetId = AssetId { + value: 0x0000000000000000000000000000000000000000000000000000000000000001, +}; + pub struct ValidInputsEvent { token_id: u64, price: u64, @@ -50,16 +58,14 @@ impl RevertError for Contract { fn failed_transfer() { let amount = 1; let address = 0x0000000000000000000000000000000000000000000000000000000000000001; - let asset = address; let user = Address::from(address); - transfer_to_address(user, asset, amount); + transfer_to_address(user, BASE_TOKEN_A, amount); } fn failed_transfer_revert() { let amount = 0; let address = 0x0000000000000000000000000000000000000000000000000000000000000001; - let asset = address; let user = Address::from(address); - transfer_to_address(user, asset, amount); + transfer_to_address(user, BASE_TOKEN_B, amount); } } diff --git a/packages/fuel-gauge/fixtures/forc-projects/script-main-args/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/script-main-args/src/main.sw index f49d0e4d83f..8cc6a229c79 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/script-main-args/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/script-main-args/src/main.sw @@ -4,7 +4,7 @@ script; use std::logging::log; fn main(foo: u8) -> u8 { - log("u8 foo"); + log(__to_str_array("u8 foo")); log(foo); foo } diff --git a/packages/fuel-gauge/fixtures/forc-projects/script-main-two-args/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/script-main-two-args/src/main.sw index 3e341a1a4f5..e6925db541c 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/script-main-two-args/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/script-main-two-args/src/main.sw @@ -7,11 +7,11 @@ struct Baz { } fn main(foo: u8, bar: Baz) -> u8 { - log("u8 foo"); + log(__to_str_array("u8 foo")); log(foo); - log("u8 bar"); + log(__to_str_array("u8 bar")); log(bar.x); - log("u8 bar"); + log(__to_str_array("u8 bar")); log(bar.x); foo + bar.x } diff --git a/packages/fuel-gauge/fixtures/forc-projects/script-with-vector/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/script-with-vector/src/main.sw index 10bf56065ba..de319bf4e8f 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/script-with-vector/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/script-with-vector/src/main.sw @@ -11,13 +11,13 @@ fn main(vector: Vec) { assert(length == 4); assert(vector.capacity() == 4); assert(vector.is_empty() == false); - log("vector.buf.ptr"); + log(__to_str_array("vector.buf.ptr")); log(vector.buf.ptr); - log("vector.buf.cap"); + log(__to_str_array("vector.buf.cap")); log(vector.buf.cap); - log("vector.len"); + log(__to_str_array("vector.len")); log(vector.len); - log("addr_of vector"); + log(__to_str_array("addr_of vector")); log(__addr_of(vector)); true }, diff --git a/packages/fuel-gauge/fixtures/forc-projects/vector-types-contract/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/vector-types-contract/src/main.sw index 9d3ef2b2f31..3fa6264d983 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/vector-types-contract/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/vector-types-contract/src/main.sw @@ -229,70 +229,70 @@ impl MyContract for Contract { vec_in_tuple: (Vec, Vec), vec_in_a_vec_in_a_struct_in_a_vec: Vec>>>, ) -> bool { - { + { let exp_u32_vec = vec_from([0, 1, 2]); require(u32_vec == exp_u32_vec, "u32_vec_error"); } - { + { let mut exp_vec_in_vec = Vec::new(); exp_vec_in_vec.push(vec_from([0, 1, 2])); exp_vec_in_vec.push(vec_from([0, 1, 2])); require(vec_in_vec == exp_vec_in_vec, "vec_in_vec err"); } - { + { let mut exp_struct_in_vec = Vec::new(); exp_struct_in_vec.push(SomeStruct { a: 0u32 }); exp_struct_in_vec.push(SomeStruct { a: 1u32 }); require(struct_in_vec == exp_struct_in_vec, "struct_in_vec err"); } - { + { let exp_vec_in_struct = SomeStruct { a: vec_from([0, 1, 2]), }; require(vec_in_struct.a == exp_vec_in_struct.a, "vec_in_struct err"); } - { + { let mut exp_array_in_vec = Vec::new(); exp_array_in_vec.push([0, 1]); exp_array_in_vec.push([0, 1]); require(array_in_vec == exp_array_in_vec, "array_in_vec err"); } - { + { let exp_vec_in_array = [vec_from([0, 1, 2]), vec_from([0, 1, 2])]; require(vec_in_array == exp_vec_in_array, "vec_in_array err"); } - { + { let exp_u32_vec = vec_from([0, 1, 2]); let exp_vec_in_enum = SomeEnum::a(exp_u32_vec); require(vec_in_enum == exp_vec_in_enum, "vec_in_enum err"); } - { + { let mut exp_enum_in_vec = Vec::new(); exp_enum_in_vec.push(SomeEnum::a(0)); exp_enum_in_vec.push(SomeEnum::a(1)); require(enum_in_vec == exp_enum_in_vec, "enum_in_vec err"); } - { + { let mut exp_tuple_in_vec = Vec::new(); exp_tuple_in_vec.push((0, 0)); exp_tuple_in_vec.push((1, 1)); require(tuple_in_vec == exp_tuple_in_vec, "tuple_in_vec err"); } - { + { let exp_vec_in_tuple = (vec_from([0, 1, 2]), vec_from([0, 1, 2])); require(vec_in_tuple == exp_vec_in_tuple, "vec_in_tuple err"); } - { + { let mut exp_vec_in_a_vec_in_a_struct_in_a_vec = Vec::new(); let mut inner_vec_1 = Vec::new(); diff --git a/packages/fuel-gauge/fixtures/forc-projects/vector-types-script/src/main.sw b/packages/fuel-gauge/fixtures/forc-projects/vector-types-script/src/main.sw index 82b78d92da0..650d9603d86 100644 --- a/packages/fuel-gauge/fixtures/forc-projects/vector-types-script/src/main.sw +++ b/packages/fuel-gauge/fixtures/forc-projects/vector-types-script/src/main.sw @@ -224,70 +224,70 @@ fn main( vec_in_tuple: (Vec, Vec), vec_in_a_vec_in_a_struct_in_a_vec: Vec>>>, ) -> bool { - { + { let exp_u32_vec = vec_from([0, 1, 2]); require(u32_vec == exp_u32_vec, "u32_vec_error"); } - { + { let mut exp_vec_in_vec = Vec::new(); exp_vec_in_vec.push(vec_from([0, 1, 2])); exp_vec_in_vec.push(vec_from([0, 1, 2])); require(vec_in_vec == exp_vec_in_vec, "vec_in_vec err"); } - { + { let mut exp_struct_in_vec = Vec::new(); exp_struct_in_vec.push(SomeStruct { a: 0u32 }); exp_struct_in_vec.push(SomeStruct { a: 1u32 }); require(struct_in_vec == exp_struct_in_vec, "struct_in_vec err"); } - { + { let exp_vec_in_struct = SomeStruct { a: vec_from([0, 1, 2]), }; require(vec_in_struct.a == exp_vec_in_struct.a, "vec_in_struct err"); } - { + { let mut exp_array_in_vec = Vec::new(); exp_array_in_vec.push([0, 1]); exp_array_in_vec.push([0, 1]); require(array_in_vec == exp_array_in_vec, "array_in_vec err"); } - { + { let exp_vec_in_array = [vec_from([0, 1, 2]), vec_from([0, 1, 2])]; require(vec_in_array == exp_vec_in_array, "vec_in_array err"); } - { + { let exp_u32_vec = vec_from([0, 1, 2]); let exp_vec_in_enum = SomeEnum::a(exp_u32_vec); require(vec_in_enum == exp_vec_in_enum, "vec_in_enum err"); } - { + { let mut exp_enum_in_vec = Vec::new(); exp_enum_in_vec.push(SomeEnum::a(0)); exp_enum_in_vec.push(SomeEnum::a(1)); require(enum_in_vec == exp_enum_in_vec, "enum_in_vec err"); } - { + { let mut exp_tuple_in_vec = Vec::new(); exp_tuple_in_vec.push((0, 0)); exp_tuple_in_vec.push((1, 1)); require(tuple_in_vec == exp_tuple_in_vec, "tuple_in_vec err"); } - { + { let exp_vec_in_tuple = (vec_from([0, 1, 2]), vec_from([0, 1, 2])); require(vec_in_tuple == exp_vec_in_tuple, "vec_in_tuple err"); } - { + { let mut exp_vec_in_a_vec_in_a_struct_in_a_vec = Vec::new(); let mut inner_vec_1 = Vec::new(); diff --git a/packages/fuel-gauge/src/raw-slice.test.ts b/packages/fuel-gauge/src/raw-slice.test.ts index 6523b3ede37..2d1d1e89c6c 100644 --- a/packages/fuel-gauge/src/raw-slice.test.ts +++ b/packages/fuel-gauge/src/raw-slice.test.ts @@ -122,7 +122,8 @@ describe('Raw Slice Tests', () => { expect(finalPredicateBalance.lte(initialPredicateBalance)).toBeTruthy(); }); - it('should test bytes input [script-raw-slice]', async () => { + // see https://github.com/FuelLabs/fuels-ts/issues/1344 + it.skip('should test raw slice input [script-raw-slice]', async () => { const wallet = await setup(); type MainArgs = [number, Wrapper]; const scriptInstance = getScript('script-raw-slice', wallet); diff --git a/packages/fuel-gauge/src/script-with-vectors.test.ts b/packages/fuel-gauge/src/script-with-vectors.test.ts index 2a67e4b4a7c..edc5db4fb18 100644 --- a/packages/fuel-gauge/src/script-with-vectors.test.ts +++ b/packages/fuel-gauge/src/script-with-vectors.test.ts @@ -41,13 +41,13 @@ describe('Script With Vectors', () => { expect(formattedLog).toEqual([ 7, 'vector.buf.ptr', - 11288, + 11304, 'vector.buf.cap', 4, 'vector.len', 4, 'addr_of vector', - 11264, + 11280, ]); }); diff --git a/packages/versions/src/lib/getSupportedVersions.ts b/packages/versions/src/lib/getSupportedVersions.ts index 39242770370..82cff5babe0 100644 --- a/packages/versions/src/lib/getSupportedVersions.ts +++ b/packages/versions/src/lib/getSupportedVersions.ts @@ -1,6 +1,6 @@ export function getSupportedVersions() { return { - FORC: '0.44.0', + FORC: '0.46.1', FUEL_CORE: '0.20.7', FUELS: '0.63.0', };