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

feat!: deprecate multiple encoding version support for configurable constants #2040

Merged
merged 10 commits into from
Apr 11, 2024
5 changes: 5 additions & 0 deletions .changeset/brave-rice-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/abi-coder": minor
---

feat!: deprecate multiple encoding version support for configurable constants
4 changes: 3 additions & 1 deletion packages/abi-coder/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AbiCoder } from './AbiCoder';
import { FunctionFragment } from './FunctionFragment';
import type { InputValue } from './encoding/coders/AbstractCoder';
import type { JsonAbi, JsonAbiConfigurable } from './types/JsonAbi';
import { ENCODING_V0 } from './utils/constants';
import { findTypeById } from './utils/json-abi';

export class Interface<TAbi extends JsonAbi = JsonAbi> {
Expand Down Expand Up @@ -99,7 +100,8 @@ export class Interface<TAbi extends JsonAbi = JsonAbi> {

return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
isRightPadded: true,
encoding: this.jsonAbi.encoding,
petertonysmith94 marked this conversation as resolved.
Show resolved Hide resolved
// TODO: Review support for configurables in v1 encoding when it becomes available
encoding: ENCODING_V0,
danielbate marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down
24 changes: 23 additions & 1 deletion packages/fuel-gauge/src/experimental-contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { readFileSync } from 'fs';
import type { Contract } from 'fuels';
import { bn } from 'fuels';
import { ContractFactory, bn } from 'fuels';
import { join } from 'path';

import { setup } from './utils';

let contractInstance: Contract;
let contractFactory: ContractFactory;

const U8_MAX = 2 ** 8 - 1;
const U16_MAX = 2 ** 16 - 1;
Expand All @@ -29,6 +30,7 @@ describe('Experimental Contract', () => {
const abi = JSON.parse(readFileSync(`${path}-abi.json`, 'utf8'));

contractInstance = await setup({ contractBytecode, abi });
contractFactory = new ContractFactory(contractBytecode, abi, contractInstance.account);
});

it('echos mixed struct with all types', async () => {
Expand Down Expand Up @@ -86,4 +88,24 @@ describe('Experimental Contract', () => {
'The transaction reverted because a "require" statement has thrown "This is a revert error".'
);
});

it('echos configurable (both encoding versions)', async () => {
const param = [1, 2, 3, 'four'];
const { value } = await contractInstance.functions.echo_configurable(param).call();

expect(value).toStrictEqual(param);

const configurableParam = [5, 6, 7, 'fuel'];
const configurableConstants = {
CONF: configurableParam,
};
const configurableContractInstance = await contractFactory.deployContract({
configurableConstants,
});
const { value: configurableValue } = await configurableContractInstance.functions
.echo_configurable(configurableParam)
.call();

expect(configurableValue).toStrictEqual(configurableParam);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ struct MixedStruct {
str_slice: str,
}

configurable {
CONF: (u8, u16, u32, str[4]) = (1, 2, 3, __to_str_array("four")),
}

abi MyContract {
fn echo_struct(param: MixedStruct) -> MixedStruct;
fn test_revert() -> bool;
fn echo_configurable(param: (u8, u16, u32, str[4])) -> (u8, u16, u32, str[4]);
}

impl MyContract for Contract {
Expand All @@ -79,4 +84,16 @@ impl MyContract for Contract {
require(false, "This is a revert error");
true
}

fn echo_configurable(param: (u8, u16, u32, str[4])) -> (u8, u16, u32, str[4]) {
assert_eq(param.0, CONF.0);
assert_eq(param.1, CONF.1);
assert_eq(param.2, CONF.2);

let param_str: str = from_str_array(param.3);
let conf_str: str = from_str_array(CONF.3);
assert_eq(param_str, conf_str);

CONF
}
}
Loading