From 4e2b088c56bbdaf66e2b811e092d22869666111c Mon Sep 17 00:00:00 2001 From: Maciej Zielinski Date: Tue, 2 Feb 2021 15:34:40 +0100 Subject: [PATCH] SDK v1.0.15, change getters to functions for value and remainder on CLValue. --- packages/sdk/CHANGELOG.md | 13 +++ packages/sdk/package.json | 2 +- packages/sdk/src/lib/CLValue.ts | 112 +++++++++++----------- packages/sdk/src/lib/RuntimeArgs.ts | 14 +-- packages/sdk/src/lib/StoredValue.ts | 2 +- packages/sdk/src/lib/option.ts | 13 ++- packages/sdk/test/lib/StoredValue.test.ts | 2 +- packages/sdk/test/lib/byterepr.test.ts | 88 +++++++++-------- 8 files changed, 137 insertions(+), 109 deletions(-) create mode 100644 packages/sdk/CHANGELOG.md diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md new file mode 100644 index 00000000..9511aded --- /dev/null +++ b/packages/sdk/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +All notable changes to casper-client-sdk. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.0.15] +### Added +- Start using CHANGELOG.md. + +### Changed +- Change CLValue's `value` to `value()` and `remainder` to `remainder()`. \ No newline at end of file diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 6979f704..bbff5983 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "casper-client-sdk", - "version": "1.0.14", + "version": "1.0.15", "license": "Apache 2.0", "description": "SDK to interact with the Casper blockchain", "main": "dist/index.js", diff --git a/packages/sdk/src/lib/CLValue.ts b/packages/sdk/src/lib/CLValue.ts index edd65d03..bec88bd8 100644 --- a/packages/sdk/src/lib/CLValue.ts +++ b/packages/sdk/src/lib/CLValue.ts @@ -133,7 +133,7 @@ export class Result { return new Result(val, rem, FromBytesError.Ok); } - get remainder(): Uint8Array { + public remainder(): Uint8Array { if (this.rem === null) { throw new Error("Don't have remainder"); } @@ -143,7 +143,7 @@ export class Result { /** * Assumes that reference wrapper contains a value and then returns it */ - get value(): T { + public value(): T { if (!this.hasValue()) { throw new Error("Don't have value"); } @@ -399,11 +399,11 @@ export class StringValue extends CLTypedAndToBytes { if (res.hasError()) { return Result.Err(res.error); } - const len = res.value.val.toNumber(); - const str = Buffer.from(res.remainder.subarray(0, len)).toString('utf8'); + const len = res.value().val.toNumber(); + const str = Buffer.from(res.remainder().subarray(0, len)).toString('utf8'); return Result.Ok( new StringValue(str), - res.remainder.subarray(len) + res.remainder().subarray(len) ); } } @@ -486,7 +486,7 @@ const fromBytesSimpleType = ( if (innerRes.hasError()) { return Result.Err(innerRes.error); } else { - return Result.Ok(innerRes.value, innerRes.remainder); + return Result.Ok(innerRes.value(), innerRes.remainder()); } }; @@ -514,16 +514,16 @@ export class List extends CLTypedAndToBytes { if (u32Res.hasError()) { return Result.Err(u32Res.error); } - const size = u32Res.value.val.toNumber(); + const size = u32Res.value().val.toNumber(); const vec = []; - let remainder = u32Res.remainder; + let remainder = u32Res.remainder(); for (let i = 0; i < size; i++) { const v = fromBytesByCLType(type.innerType, remainder); if (v.hasError()) { return Result.Err(v.error); } - vec.push(v.value); - remainder = v.remainder; + vec.push(v.value()); + remainder = v.remainder(); } return Result.Ok(new List(vec), remainder); } @@ -547,8 +547,8 @@ export class Tuple1 extends CLTypedAndToBytes { if (innerRes.hasError()) { return Result.Err(innerRes.error); } - const tuple = new Tuple1(innerRes.value); - return Result.Ok(tuple, innerRes.remainder); + const tuple = new Tuple1(innerRes.value()); + return Result.Ok(tuple, innerRes.remainder()); } } @@ -570,12 +570,12 @@ export class Tuple2 extends CLTypedAndToBytes { if (t0Res.hasError()) { return Result.Err(t0Res.error); } - const t1Res = fromBytesByCLType(type.t1, t0Res.remainder); + const t1Res = fromBytesByCLType(type.t1, t0Res.remainder()); if (t1Res.hasError()) { return Result.Err(t1Res.error); } - const tuple = new Tuple2(t0Res.value, t1Res.value); - return Result.Ok(tuple, t1Res.remainder); + const tuple = new Tuple2(t0Res.value(), t1Res.value()); + return Result.Ok(tuple, t1Res.remainder()); } } @@ -605,16 +605,16 @@ export class Tuple3 extends CLTypedAndToBytes { if (t0Res.hasError()) { return Result.Err(t0Res.error); } - const t1Res = fromBytesByCLType(type.t1, t0Res.remainder); + const t1Res = fromBytesByCLType(type.t1, t0Res.remainder()); if (t1Res.hasError()) { return Result.Err(t1Res.error); } - const t2Res = fromBytesByCLType(type.t2, t1Res.remainder); + const t2Res = fromBytesByCLType(type.t2, t1Res.remainder()); if (t2Res.hasError()) { return Result.Err(t2Res.error); } - const tuple = new Tuple3(t0Res.value, t1Res.value, t2Res.value); - return Result.Ok(tuple, t2Res.remainder); + const tuple = new Tuple3(t0Res.value(), t1Res.value(), t2Res.value()); + return Result.Ok(tuple, t2Res.remainder()); } } @@ -776,21 +776,21 @@ export class MapValue extends CLTypedAndToBytes { if (u32Res.hasError()) { return Result.Err(u32Res.error); } - const size = u32Res.value.val.toNumber(); + const size = u32Res.value().val.toNumber(); const vec: MapEntry[] = []; - let remainder = u32Res.remainder; + let remainder = u32Res.remainder(); for (let i = 0; i < size; i++) { const keyRes = fromBytesByCLType(type.keyType, remainder); if (keyRes.hasError()) { return Result.Err(keyRes.error); } - remainder = keyRes.remainder; + remainder = keyRes.remainder(); const valueRes = fromBytesByCLType(type.valueType, remainder); if (valueRes.hasError()) { return Result.Err(valueRes.error); } - remainder = valueRes.remainder; - vec.push({ key: keyRes.value, value: valueRes.value }); + remainder = valueRes.remainder(); + vec.push({ key: keyRes.value(), value: valueRes.value() }); } return Result.Ok(new MapValue(vec), remainder); } @@ -1085,8 +1085,8 @@ export class CLTypeHelper { } return Result.Ok( - CLTypeHelper.option(innerTypeRes.value), - innerTypeRes.remainder + CLTypeHelper.option(innerTypeRes.value()), + innerTypeRes.remainder() ); } case ComplexType.List: { @@ -1097,8 +1097,8 @@ export class CLTypeHelper { } return Result.Ok( - CLTypeHelper.list(innerTypeRes.value), - innerTypeRes.remainder + CLTypeHelper.list(innerTypeRes.value()), + innerTypeRes.remainder() ); } case ComplexType.ByteArray: { @@ -1108,8 +1108,8 @@ export class CLTypeHelper { return Result.Err(sizeRes.error); } return Result.Ok( - CLTypeHelper.byteArray(sizeRes.value.val.toNumber()), - sizeRes.remainder + CLTypeHelper.byteArray(sizeRes.value().val.toNumber()), + sizeRes.remainder() ); } case ComplexType.Result: @@ -1121,13 +1121,13 @@ export class CLTypeHelper { if (keyTypeRes.hasError()) { return Result.Err(keyTypeRes.error); } - const valueTypeRes = CLTypeHelper.fromBytes(keyTypeRes.remainder); + const valueTypeRes = CLTypeHelper.fromBytes(keyTypeRes.remainder()); if (valueTypeRes.hasError()) { return Result.Err(valueTypeRes.error); } return Result.Ok( - CLTypeHelper.map(keyTypeRes.value, valueTypeRes.value), - valueTypeRes.remainder + CLTypeHelper.map(keyTypeRes.value(), valueTypeRes.value()), + valueTypeRes.remainder() ); } @@ -1139,8 +1139,8 @@ export class CLTypeHelper { } return Result.Ok( - CLTypeHelper.tuple1(innerTypeRes.value), - innerTypeRes.remainder + CLTypeHelper.tuple1(innerTypeRes.value()), + innerTypeRes.remainder() ); } case ComplexType.Tuple2: { @@ -1150,14 +1150,14 @@ export class CLTypeHelper { return Result.Err(innerType1Res.error); } - const innerType2Res = CLTypeHelper.fromBytes(innerType1Res.remainder); + const innerType2Res = CLTypeHelper.fromBytes(innerType1Res.remainder()); if (innerType2Res.hasError()) { return Result.Err(innerType2Res.error); } return Result.Ok( - CLTypeHelper.tuple2(innerType1Res.value, innerType2Res.value), - innerType2Res.remainder + CLTypeHelper.tuple2(innerType1Res.value(), innerType2Res.value()), + innerType2Res.remainder() ); } case ComplexType.Tuple3: { @@ -1167,23 +1167,23 @@ export class CLTypeHelper { return Result.Err(innerType1Res.error); } - const innerType2Res = CLTypeHelper.fromBytes(innerType1Res.remainder); + const innerType2Res = CLTypeHelper.fromBytes(innerType1Res.remainder()); if (innerType2Res.hasError()) { return Result.Err(innerType2Res.error); } - const innerType3Res = CLTypeHelper.fromBytes(innerType1Res.remainder); + const innerType3Res = CLTypeHelper.fromBytes(innerType1Res.remainder()); if (innerType3Res.hasError()) { return Result.Err(innerType3Res.error); } return Result.Ok( CLTypeHelper.tuple3( - innerType1Res.value, - innerType2Res.value, - innerType3Res.value + innerType1Res.value(), + innerType2Res.value(), + innerType3Res.value() ), - innerType3Res.remainder + innerType3Res.remainder() ); } case ComplexType.Any: @@ -1463,7 +1463,7 @@ const jsonToCLType = (json: any): CLType => { function deserializeCLValue(_a: any, _b: any) { const v = fromBytesByCLType(_a.clType, decodeBase16(_a.bytes)); - const ret = CLValue.fromT(v.value); + const ret = CLValue.fromT(v.value()); return ret; } @@ -1506,7 +1506,7 @@ export class CLValue implements ToBytes { this.bytes = encodeBase16(this.value.toBytes()); } - public get clValueBytes() { + public clValueBytes() { return this.value.toBytes(); } @@ -1519,7 +1519,7 @@ export class CLValue implements ToBytes { */ public toBytes() { return concat([ - toBytesArrayU8(this.clValueBytes), + toBytesArrayU8(this.clValueBytes()), CLTypeHelper.toBytesHelper(this.clType) ]); } @@ -1529,13 +1529,13 @@ export class CLValue implements ToBytes { if (bytesRes.hasError()) { return Result.Err(bytesRes.error); } - const clTypeRes = CLTypeHelper.fromBytes(bytesRes.remainder); + const clTypeRes = CLTypeHelper.fromBytes(bytesRes.remainder()); if (clTypeRes.hasError()) { return Result.Err(clTypeRes.error); } - const v = fromBytesByCLType(clTypeRes.value, bytesRes.value.rawBytes); - const clValue = new CLValue(v.value, clTypeRes.value); - return Result.Ok(clValue, clTypeRes.remainder); + const v = fromBytesByCLType(clTypeRes.value(), bytesRes.value().rawBytes); + const clValue = new CLValue(v.value(), clTypeRes.value()); + return Result.Ok(clValue, clTypeRes.remainder()); } protected reconstruct() { @@ -1543,7 +1543,7 @@ export class CLValue implements ToBytes { if (v.hasError()) { throw new Error('Failed to deserialize CLValue'); } - this.value = v.value; + this.value = v.value(); } public static bool = (b: boolean) => { @@ -1872,16 +1872,16 @@ export class KeyValue extends CLTypedAndToBytes { if (urefResult.hasError()) { return Result.Err(urefResult.error); } - const key = KeyValue.fromURef(urefResult.value); - return Result.Ok(key, urefResult.remainder); + const key = KeyValue.fromURef(urefResult.value()); + return Result.Ok(key, urefResult.remainder()); } else if (tag === KeyVariant.ACCOUNT_ID) { const accountHashBytes = bytes.subarray(1); const accountHashResult = AccountHash.fromBytes(accountHashBytes); if (accountHashResult.hasError()) { return Result.Err(accountHashResult.error); } - const key = KeyValue.fromAccount(accountHashResult.value); - return Result.Ok(key, accountHashResult.remainder); + const key = KeyValue.fromAccount(accountHashResult.value()); + return Result.Ok(key, accountHashResult.remainder()); } else { return Result.Err(FromBytesError.FormattingError); } diff --git a/packages/sdk/src/lib/RuntimeArgs.ts b/packages/sdk/src/lib/RuntimeArgs.ts index 7105d99a..5a621c04 100644 --- a/packages/sdk/src/lib/RuntimeArgs.ts +++ b/packages/sdk/src/lib/RuntimeArgs.ts @@ -20,13 +20,13 @@ export class NamedArg implements ToBytes { if (nameRes.hasError()) { return Result.Err(nameRes.error); } - const clValueRes = CLValue.fromBytes(nameRes.remainder); + const clValueRes = CLValue.fromBytes(nameRes.remainder()); if (clValueRes.hasError()) { return Result.Err(clValueRes.error); } return Result.Ok( - new NamedArg(nameRes.value.val, clValueRes.value), - clValueRes.remainder + new NamedArg(nameRes.value().val, clValueRes.value()), + clValueRes.remainder() ); } } @@ -91,16 +91,16 @@ export class RuntimeArgs implements ToBytes { if (sizeRes.hasError()) { return Result.Err(sizeRes.error); } - const size = sizeRes.value.val.toNumber(); - let remainBytes = sizeRes.remainder; + const size = sizeRes.value().val.toNumber(); + let remainBytes = sizeRes.remainder(); const res: NamedArg[] = []; for (let i = 0; i < size; i++) { const namedArgRes = NamedArg.fromBytes(remainBytes); if (namedArgRes.hasError()) { return Result.Err(namedArgRes.error); } - res.push(namedArgRes.value); - remainBytes = namedArgRes.remainder; + res.push(namedArgRes.value()); + remainBytes = namedArgRes.remainder(); } return Result.Ok(RuntimeArgs.fromNamedArgs(res), remainBytes); } diff --git a/packages/sdk/src/lib/StoredValue.ts b/packages/sdk/src/lib/StoredValue.ts index 239b5adf..fcac11d2 100644 --- a/packages/sdk/src/lib/StoredValue.ts +++ b/packages/sdk/src/lib/StoredValue.ts @@ -31,7 +31,7 @@ class ActionThresholds { */ @jsonObject class AccountJson { - get accountHash(): string { + public accountHash(): string { return this._accountHash; } diff --git a/packages/sdk/src/lib/option.ts b/packages/sdk/src/lib/option.ts index 1d51573c..49abe80d 100644 --- a/packages/sdk/src/lib/option.ts +++ b/packages/sdk/src/lib/option.ts @@ -88,17 +88,20 @@ export class Option extends CLTypedAndToBytes { if (u8Res.hasError()) { return Result.Err(u8Res.error); } - const optionTag = u8Res.value.val.toNumber(); + const optionTag = u8Res.value().val.toNumber(); if (optionTag === OPTION_TAG_NONE) { - return Result.Ok(new Option(null, type.innerType), u8Res.remainder); + return Result.Ok(new Option(null, type.innerType), u8Res.remainder()); } else if (optionTag === OPTION_TAG_SOME) { - const innerValueRes = fromBytesByCLType(type.innerType, u8Res.remainder); + const innerValueRes = fromBytesByCLType( + type.innerType, + u8Res.remainder() + ); if (innerValueRes.hasError()) { return Result.Err(innerValueRes.error); } return Result.Ok( - new Option(innerValueRes.value, type.innerType), - innerValueRes.remainder + new Option(innerValueRes.value(), type.innerType), + innerValueRes.remainder() ); } else { return Result.Err(FromBytesError.FormattingError); diff --git a/packages/sdk/test/lib/StoredValue.test.ts b/packages/sdk/test/lib/StoredValue.test.ts index bb70501e..d3b4f453 100644 --- a/packages/sdk/test/lib/StoredValue.test.ts +++ b/packages/sdk/test/lib/StoredValue.test.ts @@ -49,7 +49,7 @@ describe('StoredValue', () => { const serializer = new TypedJSON(StoredValue); const storedValue = serializer.parse(mockJson); expect(storedValue?.Account).not.eq(undefined); - expect(storedValue?.Account?.accountHash).to.eq( + expect(storedValue?.Account?.accountHash()).to.eq( mockJson.Account.account_hash ); expect(storedValue?.Account?.actionThresholds).not.eq(undefined); diff --git a/packages/sdk/test/lib/byterepr.test.ts b/packages/sdk/test/lib/byterepr.test.ts index e9db2d76..b1c62fe2 100644 --- a/packages/sdk/test/lib/byterepr.test.ts +++ b/packages/sdk/test/lib/byterepr.test.ts @@ -43,13 +43,13 @@ describe(`numbers' toBytes`, () => { it('should be able to serialize/deserialize u8', () => { let bytesU8 = toBytesU8(10); expect(bytesU8).to.deep.eq(Uint8Array.from([0x0a])); - expect(U8.fromBytes(bytesU8).value.toBytes()).to.deep.eq( + expect(U8.fromBytes(bytesU8).value().toBytes()).to.deep.eq( CLTypedAndToBytesHelper.u8(10).toBytes() ); bytesU8 = toBytesU8(255); expect(bytesU8).to.deep.eq(Uint8Array.from([0xff])); - expect(U8.fromBytes(bytesU8).value.toBytes()).to.deep.eq( + expect(U8.fromBytes(bytesU8).value().toBytes()).to.deep.eq( CLTypedAndToBytesHelper.u8(255).toBytes() ); @@ -59,17 +59,17 @@ describe(`numbers' toBytes`, () => { it('should be able to serialize/deserialize u32', () => { let bytesU32 = toBytesU32(0xf0e0_d0c0); expect(bytesU32).to.deep.eq(Uint8Array.from([0xc0, 0xd0, 0xe0, 0xf0])); - expect(U32.fromBytes(bytesU32).value.toBytes()).to.deep.eq( + expect(U32.fromBytes(bytesU32).value().toBytes()).to.deep.eq( CLTypedAndToBytesHelper.u32(0xf0e0_d0c0).toBytes() ); bytesU32 = toBytesU32(100000); expect(bytesU32).to.deep.eq(Uint8Array.from([160, 134, 1, 0])); - expect(U32.fromBytes(bytesU32).value.toBytes()).to.deep.eq( + expect(U32.fromBytes(bytesU32).value().toBytes()).to.deep.eq( CLTypedAndToBytesHelper.u32(100000).toBytes() ); bytesU32 = toBytesU32(0); expect(bytesU32).to.deep.eq(Uint8Array.from([0, 0, 0, 0])); - expect(U32.fromBytes(bytesU32).value.toBytes()).to.deep.eq( + expect(U32.fromBytes(bytesU32).value().toBytes()).to.deep.eq( CLTypedAndToBytesHelper.u32(0).toBytes() ); }); @@ -77,22 +77,22 @@ describe(`numbers' toBytes`, () => { it('should be able to serialize/deserialize i32', () => { let bytesI32 = toBytesI32(-100000); expect(bytesI32).to.deep.eq(Uint8Array.from([96, 121, 254, 255])); - expect(I32.fromBytes(bytesI32).value.toBytes()).to.deep.eq( + expect(I32.fromBytes(bytesI32).value().toBytes()).to.deep.eq( CLTypedAndToBytesHelper.i32(-100000).toBytes() ); bytesI32 = toBytesI32(100000); expect(bytesI32).to.deep.eq(Uint8Array.from([160, 134, 1, 0])); - expect(I32.fromBytes(bytesI32).value.toBytes()).to.deep.eq( + expect(I32.fromBytes(bytesI32).value().toBytes()).to.deep.eq( CLTypedAndToBytesHelper.i32(100000).toBytes() ); bytesI32 = toBytesI32(0); expect(bytesI32).to.deep.eq(Uint8Array.from([0, 0, 0, 0])); - expect(I32.fromBytes(bytesI32).value.toBytes()).to.deep.eq( + expect(I32.fromBytes(bytesI32).value().toBytes()).to.deep.eq( CLTypedAndToBytesHelper.i32(0).toBytes() ); bytesI32 = toBytesI32(-1); expect(bytesI32).to.deep.eq(Uint8Array.from([255, 255, 255, 255])); - expect(I32.fromBytes(bytesI32).value.toBytes()).to.deep.eq( + expect(I32.fromBytes(bytesI32).value().toBytes()).to.deep.eq( CLTypedAndToBytesHelper.i32(-1).toBytes() ); }); @@ -102,14 +102,14 @@ describe(`numbers' toBytes`, () => { expect(bytesI64).to.deep.eq( Uint8Array.from([57, 20, 94, 139, 1, 121, 193, 2]) ); - expect(I64.fromBytes(bytesI64).value.toBytes()).to.deep.eq( + expect(I64.fromBytes(bytesI64).value().toBytes()).to.deep.eq( CLTypedAndToBytesHelper.i64('198572906121139257').toBytes() ); bytesI64 = toBytesI64('-4009477689550808'); expect(bytesI64).to.deep.eq( Uint8Array.from([40, 88, 148, 186, 102, 193, 241, 255]) ); - expect(I64.fromBytes(bytesI64).value.toBytes()).to.deep.equal( + expect(I64.fromBytes(bytesI64).value().toBytes()).to.deep.equal( CLTypedAndToBytesHelper.i64('-4009477689550808').toBytes() ); }); @@ -119,14 +119,14 @@ describe(`numbers' toBytes`, () => { expect(bytesU64).to.deep.eq( Uint8Array.from([57, 20, 214, 178, 212, 118, 11, 197]) ); - expect(U64.fromBytes(bytesU64).value.toBytes()).to.deep.equal( + expect(U64.fromBytes(bytesU64).value().toBytes()).to.deep.equal( CLTypedAndToBytesHelper.u64('14198572906121139257').toBytes() ); bytesU64 = toBytesU64('9834009477689550808'); expect(bytesU64).to.deep.eq( Uint8Array.from([216, 167, 130, 99, 132, 107, 121, 136]) ); - expect(U64.fromBytes(bytesU64).value.toBytes()).to.deep.equal( + expect(U64.fromBytes(bytesU64).value().toBytes()).to.deep.equal( CLTypedAndToBytesHelper.u64('9834009477689550808').toBytes() ); }); @@ -134,21 +134,21 @@ describe(`numbers' toBytes`, () => { it('should be able to serialize/deserialize u128', () => { let bytesU128 = toBytesU128(100000); expect(bytesU128).to.deep.eq(Uint8Array.from([3, 160, 134, 1])); - expect(U128.fromBytes(bytesU128).value.toBytes()).to.deep.equal( + expect(U128.fromBytes(bytesU128).value().toBytes()).to.deep.equal( CLTypedAndToBytesHelper.u128(100000).toBytes() ); bytesU128 = toBytesU128(0xf0e0_d0c0_0000); expect(bytesU128).to.deep.eq( Uint8Array.from([6, 0, 0, 0xc0, 0xd0, 0xe0, 0xf0]) ); - expect(U128.fromBytes(bytesU128).value.toBytes()).to.deep.equal( + expect(U128.fromBytes(bytesU128).value().toBytes()).to.deep.equal( CLTypedAndToBytesHelper.u128(0xf0e0_d0c0_0000).toBytes() ); bytesU128 = toBytesU128(0x0000_f0e0_d0c0_0000); expect(bytesU128).to.deep.eq( Uint8Array.from([6, 0, 0, 0xc0, 0xd0, 0xe0, 0xf0]) ); - expect(U128.fromBytes(bytesU128).value.toBytes()).to.deep.equal( + expect(U128.fromBytes(bytesU128).value().toBytes()).to.deep.equal( CLTypedAndToBytesHelper.u128(0x0000_f0e0_d0c0_0000).toBytes() ); }); @@ -174,7 +174,7 @@ describe(`numbers' toBytes`, () => { 149 ]) ); - expect(StringValue.fromBytes(bytesString).value.toBytes()).to.deep.equal( + expect(StringValue.fromBytes(bytesString).value().toBytes()).to.deep.equal( CLTypedAndToBytesHelper.string('test_测试').toBytes() ); }); @@ -183,7 +183,7 @@ describe(`numbers' toBytes`, () => { const unit = CLTypedAndToBytesHelper.unit(); const bytesUnit = unit.toBytes(); expect(bytesUnit).to.deep.eq(Uint8Array.from([])); - expect(Unit.fromBytes(bytesUnit).value.toBytes()).to.deep.equal( + expect(Unit.fromBytes(bytesUnit).value().toBytes()).to.deep.equal( CLTypedAndToBytesHelper.unit().toBytes() ); }); @@ -250,10 +250,10 @@ describe(`numbers' toBytes`, () => { ]) ); - expect(KeyValue.fromBytes(bytes).value?.uRef?.uRefAddr).to.deep.equal( + expect(KeyValue.fromBytes(bytes).value()?.uRef?.uRefAddr).to.deep.equal( decodeBase16(urefAddr) ); - expect(KeyValue.fromBytes(bytes).value?.uRef?.accessRights).to.deep.equal( + expect(KeyValue.fromBytes(bytes).value()?.uRef?.accessRights).to.deep.equal( AccessRights.READ_ADD_WRITE ); }); @@ -265,7 +265,7 @@ describe(`numbers' toBytes`, () => { 1, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42 ]); expect(keyHash.toBytes()).to.deep.eq(expectedBytes); - expect(KeyValue.fromBytes(expectedBytes).value).to.deep.eq(keyHash); + expect(KeyValue.fromBytes(expectedBytes).value()).to.deep.eq(keyHash); }); it('should serialize/deserialize Account variant of Key correctly', () => { @@ -278,7 +278,7 @@ describe(`numbers' toBytes`, () => { ]); expect(keyAccount.toBytes()).to.deep.eq(expectedBytes); - expect(KeyValue.fromBytes(expectedBytes).value).to.deep.eq(keyAccount); + expect(KeyValue.fromBytes(expectedBytes).value()).to.deep.eq(keyAccount); }); it('should serialize DeployHash correctly', () => { @@ -331,7 +331,7 @@ describe(`numbers' toBytes`, () => { // prettier-ignore const expectedBytes = Uint8Array.from([255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 7]); expect(uref.toBytes()).to.deep.equal(expectedBytes); - expect(URef.fromBytes(expectedBytes).value).to.deep.eq(uref); + expect(URef.fromBytes(expectedBytes).value()).to.deep.eq(uref); }); it('should serialize/deserialize Tuple1 correctly', () => { @@ -345,14 +345,18 @@ describe(`numbers' toBytes`, () => { Tuple1.fromBytes( CLTypeHelper.tuple1(CLTypeHelper.string()), expectedBytes - ).value.clType() + ) + .value() + .clType() ).to.deep.equal(tuple.clType()); expect( Tuple1.fromBytes( CLTypeHelper.tuple1(CLTypeHelper.string()), expectedBytes - ).value.toBytes() + ) + .value() + .toBytes() ).to.deep.equal(tuple.toBytes()); }); @@ -369,14 +373,18 @@ describe(`numbers' toBytes`, () => { Tuple2.fromBytes( CLTypeHelper.tuple2(CLTypeHelper.string(), CLTypeHelper.u64()), expectedBytes - ).value.clType() + ) + .value() + .clType() ).to.deep.equal(tuple2.clType()); expect( Tuple2.fromBytes( CLTypeHelper.tuple2(CLTypeHelper.string(), CLTypeHelper.u64()), expectedBytes - ).value.toBytes() + ) + .value() + .toBytes() ).to.deep.equal(tuple2.toBytes()); }); @@ -399,7 +407,9 @@ describe(`numbers' toBytes`, () => { CLTypeHelper.bool() ), expectedBytes - ).value.clType() + ) + .value() + .clType() ).to.deep.equal(tuple3.clType()); expect( @@ -410,7 +420,9 @@ describe(`numbers' toBytes`, () => { CLTypeHelper.bool() ), expectedBytes - ).value.toBytes() + ) + .value() + .toBytes() ).to.deep.equal(tuple3.toBytes()); }); @@ -425,10 +437,9 @@ describe(`numbers' toBytes`, () => { expect(list.toBytes()).to.deep.eq(expectedBytes); expect( - List.fromBytes( - CLTypeHelper.list(CLTypeHelper.u32()), - expectedBytes - ).value.toBytes() + List.fromBytes(CLTypeHelper.list(CLTypeHelper.u32()), expectedBytes) + .value() + .toBytes() ).to.deep.eq(list.toBytes()); }); @@ -461,7 +472,9 @@ describe(`numbers' toBytes`, () => { CLTypeHelper.list(CLTypeHelper.u64()) ), expectBytes - ).value.toBytes() + ) + .value() + .toBytes() ).to.deep.eq(expectBytes); }); @@ -473,10 +486,9 @@ describe(`numbers' toBytes`, () => { expect(opt.toBytes()).to.deep.eq(expectBytes); expect( - Option.fromBytes( - CLTypeHelper.option(CLTypeHelper.string()), - expectBytes - ).value.toBytes() + Option.fromBytes(CLTypeHelper.option(CLTypeHelper.string()), expectBytes) + .value() + .toBytes() ).to.deep.eq(expectBytes); });