Skip to content

Commit

Permalink
Fix deprecated substr to substring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed Jan 8, 2024
1 parent 0fde237 commit 1b6b5cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions assembly/std/__tests__/context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
transferredCoins,
isDeployingContract,
timestamp,
json2Address,
} from '../context';
import { validateAddress } from '../utils';

Expand Down Expand Up @@ -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]);
}
});
});
4 changes: 2 additions & 2 deletions assembly/std/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address> {
str = str.substr(1, str.length - 2);
export function json2Address(str: string): Array<Address> {
str = str.substring(1, str.length - 1);

const a = str.split(',');
return a.map<Address>((x) => new Address(x.substring(1, x.length - 1)));
Expand Down

0 comments on commit 1b6b5cb

Please sign in to comment.