Skip to content

Commit

Permalink
Fix ConstantManager.set to accept array of serializable (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregLibert authored May 24, 2024
1 parent ecca530 commit ccdc140
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
14 changes: 14 additions & 0 deletions assembly/helpers/__tests__/constantKeyManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,18 @@ describe('ConstantManager - unit tests', () => {
expect(cst.tryValue().isErr()).toBe(true);
expect(cst.tryValue().error).toBe('Key not found');
});

test('get/set - array of serializable', () => {
const addr1 = new Address(
'AU12UBnqTHDQALpocVBnkPNy7y5CndUJQTLutaVDDFgMJcq5kQiKq',
);
const addr2 = new Address(
'AU12UBnqTHDQALpocVBnkPNy7y5CndUJQTLutaVDDFgMJcq5kQiKr',
);

const addresses = new ConstantManager<Array<Address>, u8, Address>();
addresses.set([addr1, addr2]);

expect(addresses.mustValue()).toStrictEqual([addr1, addr2]);
});
});
2 changes: 1 addition & 1 deletion assembly/helpers/constantKeyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ export class ConstantManager<TValue, TKey = u8, TArray = void> {
* @param value - The value to store. Must be an A
*/
public set(value: TValue): void {
Storage.set(this.key, new Args().add(value).serialize());
Storage.set(this.key, new Args().add<TValue, TArray>(value).serialize());
}
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"devDependencies": {
"@as-pect/cli": "^8.1.0",
"@massalabs/as-transformer": "^0.3.2",
"@massalabs/as-types": "^2.0.1-dev.20240521132240",
"@massalabs/as-types": "^2.0.1-dev.20240524080933",
"@massalabs/eslint-config": "^0.0.8",
"@massalabs/prettier-config-as": "^0.0.2",
"as-bignum": "^0.2.40",
Expand Down

0 comments on commit ccdc140

Please sign in to comment.