From 1b6b5cb1979ae102ada2e3d63e1cdca069b87597 Mon Sep 17 00:00:00 2001 From: Senji888 <44082144+Ben-Rey@users.noreply.github.com> Date: Thu, 23 Nov 2023 09:41:56 +0100 Subject: [PATCH] Fix deprecated substr to substring --- assembly/std/__tests__/context.spec.ts | 17 +++++++++++++++++ assembly/std/context.ts | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/assembly/std/__tests__/context.spec.ts b/assembly/std/__tests__/context.spec.ts index 3d44a6a1..e10dd000 100644 --- a/assembly/std/__tests__/context.spec.ts +++ b/assembly/std/__tests__/context.spec.ts @@ -7,6 +7,7 @@ import { transferredCoins, isDeployingContract, timestamp, + json2Address, } from '../context'; import { validateAddress } from '../utils'; @@ -45,4 +46,20 @@ describe('Context', () => { const time = timestamp(); expect(time).toBeGreaterThan(0); }); + + test('json2Address', () => { + const jsonString = '["address1","address2","address3"]'; + const expectedOutput = [ + new Address('address1'), + new Address('address2'), + new Address('address3'), + ]; + + const result = json2Address(jsonString); + + expect(result.length).toBe(expectedOutput.length); + for (let i = 0; i < result.length; i++) { + expect(result[i]).toBe(expectedOutput[i]); + } + }); }); diff --git a/assembly/std/context.ts b/assembly/std/context.ts index 6b639e37..d8c2d775 100644 --- a/assembly/std/context.ts +++ b/assembly/std/context.ts @@ -62,8 +62,8 @@ export function isDeployingContract(): bool { * * @returns An array of `Address` objects, one for each address in the input string. */ -function json2Address(str: string): Array
{ - str = str.substr(1, str.length - 2); +export function json2Address(str: string): Array { + str = str.substring(1, str.length - 1); const a = str.split(','); return a.map((x) => new Address(x.substring(1, x.length - 1)));