diff --git a/assembly/helpers/__tests__/constantKeyManager.spec.ts b/assembly/helpers/__tests__/constantKeyManager.spec.ts index 7b249c4a..ba0a9e98 100644 --- a/assembly/helpers/__tests__/constantKeyManager.spec.ts +++ b/assembly/helpers/__tests__/constantKeyManager.spec.ts @@ -3,6 +3,7 @@ import { resetStorage } from '../../vm-mock'; import { u256 } from 'as-bignum/assembly'; import { ConstantManager } from '../constantKeyManager'; import { KeyIncrementer } from '../keyIncrementer'; +import { stringToBytes } from '@massalabs/as-types'; beforeEach(() => { resetStorage(); @@ -36,6 +37,31 @@ describe('ConstantManager - use cases', () => { expect(fee.mustValue()).toBe(100); expect(usdc.mustValue().toString()).toBe('1000000'); }); + + test('executes a basic scenario - with a tag', () => { + const tagOwner = stringToBytes('owner'); + const tagFee = stringToBytes('fee'); + const tagUsdc = stringToBytes('usdc'); + + // a key manager instance is needed to generate unique keys + const keyManager = new KeyIncrementer(); + + const owner = new ConstantManager
(keyManager, tagOwner); + const fee = new ConstantManager(keyManager, tagFee); + const usdc = new ConstantManager(keyManager, tagUsdc); + + owner.set( + new Address('AU12UBnqTHDQALpocVBnkPNy7y5CndUJQTLutaVDDFgMJcq5kQiKq'), + ); + fee.set(100); + usdc.set(u256.fromU64(1000000)); + + expect(owner.mustValue().toString()).toBe( + 'AU12UBnqTHDQALpocVBnkPNy7y5CndUJQTLutaVDDFgMJcq5kQiKq', + ); + expect(fee.mustValue()).toBe(100); + expect(usdc.mustValue().toString()).toBe('1000000'); + }); }); describe('ConstantManager - unit tests', () => { diff --git a/assembly/helpers/constantKeyManager.ts b/assembly/helpers/constantKeyManager.ts index fe12c2be..98fd1212 100644 --- a/assembly/helpers/constantKeyManager.ts +++ b/assembly/helpers/constantKeyManager.ts @@ -12,8 +12,11 @@ import { Storage } from '../std'; export class ConstantManager { public key: StaticArray; - constructor(manager: KeySequenceManager = new KeyIncrementer(0)) { - this.key = manager.nextKey(); + constructor( + manager: KeySequenceManager = new KeyIncrementer(0), + tag: StaticArray = new StaticArray(0), + ) { + this.key = manager.nextKey().concat(tag); } /**