From 286b9e1d81a883d31fffd45aa248b55bed9f0719 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 15:55:55 +0000 Subject: [PATCH 01/23] chore(deps): bump the npm_and_yarn group across 6 directories with 2 updates Bumps the npm_and_yarn group with 1 update in the / directory: [axios](https://github.com/axios/axios). Bumps the npm_and_yarn group with 1 update in the /examples/cjs directory: [axios](https://github.com/axios/axios). Bumps the npm_and_yarn group with 1 update in the /examples/esm directory: [axios](https://github.com/axios/axios). Bumps the npm_and_yarn group with 1 update in the /examples/vite directory: [braces](https://github.com/micromatch/braces). Bumps the npm_and_yarn group with 2 updates in the /examples/webpack directory: [axios](https://github.com/axios/axios) and [braces](https://github.com/micromatch/braces). Bumps the npm_and_yarn group with 1 update in the /tests/e2e/web directory: [axios](https://github.com/axios/axios). Updates `axios` from 1.7.2 to 1.7.3 - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v1.7.2...v1.7.3) Updates `axios` from 1.6.8 to 1.7.2 - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v1.7.2...v1.7.3) Updates `axios` from 1.6.8 to 1.7.2 - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v1.7.2...v1.7.3) Updates `braces` from 3.0.2 to 3.0.3 - [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md) - [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3) Updates `axios` from 1.6.8 to 1.7.2 - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v1.7.2...v1.7.3) Updates `braces` from 3.0.2 to 3.0.3 - [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md) - [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3) Updates `axios` from 1.6.8 to 1.7.2 - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v1.7.2...v1.7.3) --- updated-dependencies: - dependency-name: axios dependency-type: direct:production dependency-group: npm_and_yarn - dependency-name: axios dependency-type: indirect dependency-group: npm_and_yarn - dependency-name: axios dependency-type: indirect dependency-group: npm_and_yarn - dependency-name: braces dependency-type: indirect dependency-group: npm_and_yarn - dependency-name: axios dependency-type: indirect dependency-group: npm_and_yarn - dependency-name: braces dependency-type: indirect dependency-group: npm_and_yarn - dependency-name: axios dependency-type: indirect dependency-group: npm_and_yarn ... Signed-off-by: dependabot[bot] --- examples/cjs/yarn.lock | 6 +++--- examples/esm/yarn.lock | 6 +++--- examples/vite/yarn.lock | 24 ++++++++++++------------ examples/webpack/yarn.lock | 22 +++++++++++----------- package.json | 2 +- tests/e2e/web/yarn.lock | 6 +++--- yarn.lock | 8 ++++---- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/examples/cjs/yarn.lock b/examples/cjs/yarn.lock index 478690c5..ca268865 100644 --- a/examples/cjs/yarn.lock +++ b/examples/cjs/yarn.lock @@ -555,9 +555,9 @@ axios@1.7.2: proxy-from-env "^1.1.0" axios@^1.4.0: - version "1.6.8" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" - integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ== + version "1.7.3" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.3.tgz#a1125f2faf702bc8e8f2104ec3a76fab40257d85" + integrity sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw== dependencies: follow-redirects "^1.15.6" form-data "^4.0.0" diff --git a/examples/esm/yarn.lock b/examples/esm/yarn.lock index c6de4064..c4c85e13 100644 --- a/examples/esm/yarn.lock +++ b/examples/esm/yarn.lock @@ -540,9 +540,9 @@ axios@1.7.2: proxy-from-env "^1.1.0" axios@^1.4.0: - version "1.6.8" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" - integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ== + version "1.7.3" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.3.tgz#a1125f2faf702bc8e8f2104ec3a76fab40257d85" + integrity sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw== dependencies: follow-redirects "^1.15.6" form-data "^4.0.0" diff --git a/examples/vite/yarn.lock b/examples/vite/yarn.lock index f3ec9124..985486f7 100644 --- a/examples/vite/yarn.lock +++ b/examples/vite/yarn.lock @@ -1461,11 +1461,11 @@ brace-expansion@^2.0.1: balanced-match "^1.0.0" braces@^3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" - integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== + version "3.0.3" + resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789" + integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== dependencies: - fill-range "^7.0.1" + fill-range "^7.1.1" brorand@^1.0.1, brorand@^1.1.0: version "1.1.0" @@ -2298,10 +2298,10 @@ filelist@^1.0.4: dependencies: minimatch "^5.0.1" -fill-range@^7.0.1: - version "7.0.1" - resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40" - integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ== +fill-range@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292" + integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg== dependencies: to-regex-range "^5.0.1" @@ -4525,10 +4525,10 @@ tweetnacl@^1.0.3: resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596" integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw== -typescript@^4.9.5: - version "4.9.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" - integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== +typescript@^5.3.3: + version "5.5.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba" + integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q== undici-types@~5.26.4: version "5.26.5" diff --git a/examples/webpack/yarn.lock b/examples/webpack/yarn.lock index 496f440b..6d192111 100644 --- a/examples/webpack/yarn.lock +++ b/examples/webpack/yarn.lock @@ -2345,9 +2345,9 @@ axios@1.7.2: proxy-from-env "^1.1.0" axios@^1.4.0: - version "1.6.8" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" - integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ== + version "1.7.3" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.3.tgz#a1125f2faf702bc8e8f2104ec3a76fab40257d85" + integrity sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw== dependencies: follow-redirects "^1.15.6" form-data "^4.0.0" @@ -2515,11 +2515,11 @@ brace-expansion@^2.0.1: balanced-match "^1.0.0" braces@^3.0.2, braces@~3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" - integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== + version "3.0.3" + resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789" + integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== dependencies: - fill-range "^7.0.1" + fill-range "^7.1.1" brorand@^1.0.1, brorand@^1.1.0: version "1.1.0" @@ -3688,10 +3688,10 @@ file-loader@^6.2.0: loader-utils "^2.0.0" schema-utils "^3.0.0" -fill-range@^7.0.1: - version "7.0.1" - resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40" - integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ== +fill-range@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292" + integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg== dependencies: to-regex-range "^5.0.1" diff --git a/package.json b/package.json index a86e20b4..a405a705 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "@permaweb/aoconnect": "^0.0.57", "arbundles": "0.11.0", "arweave": "1.14.4", - "axios": "1.7.2", + "axios": "1.7.3", "axios-retry": "^4.3.0", "eventemitter3": "^5.0.1", "plimit-lit": "^3.0.1", diff --git a/tests/e2e/web/yarn.lock b/tests/e2e/web/yarn.lock index cdf427ca..c7137dfb 100644 --- a/tests/e2e/web/yarn.lock +++ b/tests/e2e/web/yarn.lock @@ -1351,9 +1351,9 @@ axios@1.7.2: proxy-from-env "^1.1.0" axios@^1.4.0: - version "1.6.8" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" - integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ== + version "1.7.3" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.3.tgz#a1125f2faf702bc8e8f2104ec3a76fab40257d85" + integrity sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw== dependencies: follow-redirects "^1.15.6" form-data "^4.0.0" diff --git a/yarn.lock b/yarn.lock index b524e48f..a9d1b6d2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2820,10 +2820,10 @@ axios-retry@^4.3.0: dependencies: is-retry-allowed "^2.2.0" -axios@1.7.2, axios@^1.4.0: - version "1.7.2" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.2.tgz#b625db8a7051fbea61c35a3cbb3a1daa7b9c7621" - integrity sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw== +axios@1.7.3, axios@^1.4.0: + version "1.7.3" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.3.tgz#a1125f2faf702bc8e8f2104ec3a76fab40257d85" + integrity sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw== dependencies: follow-redirects "^1.15.6" form-data "^4.0.0" From 4320c803bec96eedf4fe4bd5456a5eaa4ac9ae88 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Wed, 7 Aug 2024 11:47:50 -0600 Subject: [PATCH 02/23] fix(register): update spawn ant to register at end of spawn --- src/utils/ao.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/utils/ao.ts b/src/utils/ao.ts index 9a810bf6..3232de6b 100644 --- a/src/utils/ao.ts +++ b/src/utils/ao.ts @@ -59,6 +59,12 @@ export async function spawnANT({ stateContractTxId?: string; antRegistryId?: string; }): Promise { + // AoSigner is not a Contract Signer - should probably add that to the contract signer type + const registryClient = new AOProcess({ + processId: antRegistryId, + ao, + }); + //TODO: cache locally and only fetch if not cached const luaString = (await defaultArweave.transactions.getData(luaCodeTxId, { decode: true, @@ -105,6 +111,14 @@ export async function spawnANT({ }); } + await registryClient.send({ + tags: [ + { name: 'Action', value: 'Register' }, + { name: 'Process-Id', value: processId }, + ], + signer, + }); + return processId; } From 0fd3e4698ca67841542c45c47de477073dc395f5 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 8 Aug 2024 22:48:44 +0000 Subject: [PATCH 03/23] chore(release): 2.1.0-alpha.11 [skip ci] # [2.1.0-alpha.11](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0-alpha.10...v2.1.0-alpha.11) (2024-08-08) ### Bug Fixes * **register:** update spawn ant to register at end of spawn ([4320c80](https://github.com/ar-io/ar-io-sdk/commit/4320c803bec96eedf4fe4bd5456a5eaa4ac9ae88)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- src/version.ts | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc2d1494..20494271 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [2.1.0-alpha.11](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0-alpha.10...v2.1.0-alpha.11) (2024-08-08) + + +### Bug Fixes + +* **register:** update spawn ant to register at end of spawn ([4320c80](https://github.com/ar-io/ar-io-sdk/commit/4320c803bec96eedf4fe4bd5456a5eaa4ac9ae88)) + ## [2.0.2](https://github.com/ar-io/ar-io-sdk/compare/v2.0.1...v2.0.2) (2024-07-12) diff --git a/package.json b/package.json index a405a705..ce9c65bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ar.io/sdk", - "version": "2.1.0-alpha.9", + "version": "2.1.0-alpha.11", "repository": { "type": "git", "url": "git+https://github.com/ar-io/ar-io-sdk.git" diff --git a/src/version.ts b/src/version.ts index 98eb6c3c..f34308a0 100644 --- a/src/version.ts +++ b/src/version.ts @@ -17,4 +17,4 @@ // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH -export const version = '2.1.0-alpha.10'; +export const version = '2.1.0-alpha.11'; From 3b0495a3ca4420c61cf4f72c7eb451777cbaf16d Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Mon, 19 Aug 2024 10:19:54 -0600 Subject: [PATCH 04/23] fix(signing): add aosigner to contract signer --- src/common.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common.ts b/src/common.ts index cab11022..d7aedd7a 100644 --- a/src/common.ts +++ b/src/common.ts @@ -25,6 +25,8 @@ import { } from '@permaweb/aoconnect'; import { Signer } from 'arbundles'; +import { AoSigner } from './token.js'; + export type BlockHeight = number; export type SortKey = string; export type Timestamp = number; @@ -33,7 +35,7 @@ export type TransactionId = string; export type ProcessId = string; // TODO: append this with other configuration options (e.g. local vs. remote evaluation) -export type ContractSigner = Signer | Window['arweaveWallet']; +export type ContractSigner = Signer | Window['arweaveWallet'] | AoSigner; export type WithSigner> = { signer: ContractSigner; } & T; // TODO: optionally allow JWK in place of signer From 7eeeea1f74e90f0d7d405ae091f4a8237b4a91ba Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Mon, 19 Aug 2024 11:38:17 -0600 Subject: [PATCH 05/23] chore(tests): add e2e signing tests for cjs and esm --- src/utils/ao.ts | 4 ++ tests/e2e/cjs/index.test.js | 64 +++++++++++++++++- tests/e2e/esm/index.test.js | 64 +++++++++++++++++- tests/utils.ts | 129 ------------------------------------ 4 files changed, 128 insertions(+), 133 deletions(-) diff --git a/src/utils/ao.ts b/src/utils/ao.ts index 3232de6b..6dc6765a 100644 --- a/src/utils/ao.ts +++ b/src/utils/ao.ts @@ -158,6 +158,10 @@ export async function evolveANT({ } export function createAoSigner(signer: ContractSigner): AoSigner { + if (typeof signer == 'function') { + return signer; + } + if (!('publicKey' in signer)) { return createDataItemSigner(signer) as AoSigner; } diff --git a/tests/e2e/cjs/index.test.js b/tests/e2e/cjs/index.test.js index 05ab78a3..6b18f6a0 100644 --- a/tests/e2e/cjs/index.test.js +++ b/tests/e2e/cjs/index.test.js @@ -1,11 +1,21 @@ -const { describe, it } = require('node:test'); +const { describe, it, before } = require('node:test'); const assert = require('node:assert/strict'); /** * Ensure that npm link has been ran prior to running these tests * (simply running npm run test:integration will ensure npm link is ran) */ -const { IO, ioDevnetProcessId, ANTRegistry } = require('@ar.io/sdk'); +const { + IO, + ioDevnetProcessId, + ANTRegistry, + ANT, + createAoSigner, + ArweaveSigner, + WriteInteractionError, +} = require('@ar.io/sdk'); +const Arweave = require('arweave'); +const arweave = Arweave.init({}); const io = IO.init({ processId: ioDevnetProcessId, }); @@ -277,3 +287,53 @@ describe('ANTRegistry', async () => { assert(Array.isArray(affiliatedAnts.Controlled)); }); }); + +describe('Signing', async () => { + let signers = []; + before(async () => { + const jwk = await arweave.wallets.generate(); + signers = [new ArweaveSigner(jwk), createAoSigner(new ArweaveSigner(jwk))]; + }); + + it('Should be able to sign on the IO contract with all ContractSigner types', async () => { + for (const signer of signers) { + const io = IO.init({ signer }); + const res = await io + .transfer({ + target: 'QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ', + qty: 1, + }) + .catch((e) => e); + // if it is a WriteInteractionError, it means the transaction was signed contract threw an error + assert(res instanceof WriteInteractionError); + } + }); + it('Should be able to sign on ANTs with all ContractSigner types', async () => { + for (const signer of signers) { + const ant = ANT.init({ + processId: 'aWI_dq1JH7facsulLuas1X3l5dkKuWtixcZDYMw9mpg', + signer, + }); + const res = await ant + .transfer({ + target: 'aWI_dq1JH7facsulLuas1X3l5dkKuWtixcZDYMw9mpg', + qty: 1, + }) + .catch((e) => e); + // if it is a WriteInteractionError, it means the transaction was signed contract threw an error + assert(res instanceof WriteInteractionError); + } + }); + + it('Should be able to sign on ANTRegistry with all ContractSigner types', async () => { + for (const signer of signers) { + const registry = ANTRegistry.init({ + signer, + }); + const res = await registry.register({ + processId: ''.padEnd(43, '1'), + }); + assert(res.id); + } + }); +}); diff --git a/tests/e2e/esm/index.test.js b/tests/e2e/esm/index.test.js index 98feda2e..d4d934cf 100644 --- a/tests/e2e/esm/index.test.js +++ b/tests/e2e/esm/index.test.js @@ -1,6 +1,15 @@ -import { ANTRegistry, IO, ioDevnetProcessId } from '@ar.io/sdk'; +import { + ANT, + ANTRegistry, + ArweaveSigner, + IO, + WriteInteractionError, + createAoSigner, + ioDevnetProcessId, +} from '@ar.io/sdk'; +import Arweave from 'arweave'; import { strict as assert } from 'node:assert'; -import { describe, it } from 'node:test'; +import { before, describe, it } from 'node:test'; /** * Ensure that npm link has been ran prior to running these tests @@ -10,6 +19,7 @@ import { describe, it } from 'node:test'; const io = IO.init({ processId: ioDevnetProcessId, }); +const arweave = Arweave.init({}); describe('IO', async () => { it('should be able to get the process information', async () => { const epoch = await io.getInfo(); @@ -278,3 +288,53 @@ describe('ANTRegistry', async () => { assert(Array.isArray(affiliatedAnts.Controlled)); }); }); + +describe('Signing', async () => { + let signers = []; + before(async () => { + const jwk = await arweave.wallets.generate(); + signers = [new ArweaveSigner(jwk), createAoSigner(new ArweaveSigner(jwk))]; + }); + + it('Should be able to sign on the IO contract with all ContractSigner types', async () => { + for (const signer of signers) { + const io = IO.init({ signer }); + const res = await io + .transfer({ + target: 'QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ', + qty: 1, + }) + .catch((e) => e); + // if it is a WriteInteractionError, it means the transaction was signed contract threw an error + assert(res instanceof WriteInteractionError); + } + }); + it('Should be able to sign on ANTs with all ContractSigner types', async () => { + for (const signer of signers) { + const ant = ANT.init({ + processId: 'aWI_dq1JH7facsulLuas1X3l5dkKuWtixcZDYMw9mpg', + signer, + }); + const res = await ant + .transfer({ + target: 'aWI_dq1JH7facsulLuas1X3l5dkKuWtixcZDYMw9mpg', + qty: 1, + }) + .catch((e) => e); + // if it is a WriteInteractionError, it means the transaction was signed contract threw an error + assert(res instanceof WriteInteractionError); + } + }); + + it('Should be able to sign on ANTRegistry with all ContractSigner types', async () => { + for (const signer of signers) { + const registry = ANTRegistry.init({ + signer, + }); + const res = await registry.register({ + processId: ''.padEnd(43, '1'), + }); + assert(res.id); + } + }); +}); diff --git a/tests/utils.ts b/tests/utils.ts index 6e8d25ab..75b17487 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -2,138 +2,9 @@ import Arweave from 'arweave'; import { JWKInterface } from 'arweave/node/lib/wallet'; import * as fs from 'fs'; import path from 'path'; -import { ContractDeploy, SourceType, Warp } from 'warp-contracts'; - -import { WeightedObserver } from '../src/contract-state.js'; const oneYearSeconds = 60 * 60 * 24 * 365; -export async function deployANTContract({ - jwk, - address, - warp, -}: { - jwk: JWKInterface; - address: string; - warp: Warp; -}): Promise { - const src = fs.readFileSync( - path.join(__dirname, '/integration/arlocal/ant-contract/index.js'), - 'utf8', - ); - const state = JSON.parse( - fs.readFileSync( - path.join( - __dirname, - '/integration/arlocal/ant-contract/initial-state.json', - ), - 'utf8', - ), - ); - return warp.deploy({ - wallet: jwk, - src: src, - initState: JSON.stringify({ - ...state, - owner: address, - controllers: [address], - balances: { [address]: 1000000 }, - }), - evaluationManifest: { - evaluationOptions: { - sourceType: SourceType.ARWEAVE, - }, - }, - }); -} - -export async function deployArIOContract({ - jwk, - address, - warp, - arweave, -}: { - jwk: JWKInterface; - address: string; - warp: Warp; - arweave: Arweave; -}): Promise { - const currentBlockTimestamp = (await arweave.blocks.getCurrent()).timestamp; - const src = fs.readFileSync( - path.join(__dirname, '/integration/arlocal/ar-io-contract/index.js'), - 'utf8', - ); - const state = JSON.parse( - fs.readFileSync( - path.join( - __dirname, - '/integration/arlocal/ar-io-contract/initial-state.json', - ), - 'utf8', - ), - ); - - // add the wallet owner as a prescribed observer and as a gateway - const prescribedObservers: WeightedObserver[] = - state.prescribedObservers['0']; - const lastObserver: WeightedObserver = - prescribedObservers.pop() as WeightedObserver; - const newPrescribedObserver: WeightedObserver = { - ...lastObserver, - gatewayAddress: address, - observerAddress: address, - }; - const updatedPrescribedObservers = [ - ...prescribedObservers, - newPrescribedObserver, - ]; - - return warp.deploy({ - wallet: jwk, - src: src, - initState: JSON.stringify({ - ...state, - records: { - ...state.records, - 'test-record': { - contractTxId: 'I-cxQhfh0Zb9UqQNizC9PiLC41KpUeA9hjiVV02rQRw', - endTimestamp: currentBlockTimestamp + oneYearSeconds, - purchasePrice: 0, - startTimestamp: currentBlockTimestamp, - type: 'lease', - undernames: 10, - }, - 'test-extend': { - contractTxId: 'I-cxQhfh0Zb9UqQNizC9PiLC41KpUeA9hjiVV02rQRw', - endTimestamp: currentBlockTimestamp + oneYearSeconds, - purchasePrice: 0, - startTimestamp: currentBlockTimestamp, - type: 'lease', - undernames: 10, - }, - 'test-undername': { - contractTxId: 'I-cxQhfh0Zb9UqQNizC9PiLC41KpUeA9hjiVV02rQRw', - endTimestamp: currentBlockTimestamp + oneYearSeconds, - purchasePrice: 0, - startTimestamp: currentBlockTimestamp, - type: 'lease', - undernames: 10, - }, - }, - owner: address, - balances: { [address]: 100_000_000_000_000 }, - prescribedObservers: { - 0: updatedPrescribedObservers, - }, - }), - evaluationManifest: { - evaluationOptions: { - sourceType: SourceType.ARWEAVE, - }, - }, - }); -} - export async function createLocalWallet( arweave: Arweave, amount = 10_000_000_000_000, From e7108dafb7602e29833b0120c91cff73b022d31f Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Mon, 19 Aug 2024 14:05:25 -0600 Subject: [PATCH 06/23] fix(tests): dont send messages to ao in e2e tests --- tests/e2e/cjs/index.test.js | 26 +++++--------------------- tests/e2e/esm/index.test.js | 26 +++++--------------------- 2 files changed, 10 insertions(+), 42 deletions(-) diff --git a/tests/e2e/cjs/index.test.js b/tests/e2e/cjs/index.test.js index 6b18f6a0..4451774b 100644 --- a/tests/e2e/cjs/index.test.js +++ b/tests/e2e/cjs/index.test.js @@ -11,7 +11,6 @@ const { ANT, createAoSigner, ArweaveSigner, - WriteInteractionError, } = require('@ar.io/sdk'); const Arweave = require('arweave'); @@ -298,14 +297,8 @@ describe('Signing', async () => { it('Should be able to sign on the IO contract with all ContractSigner types', async () => { for (const signer of signers) { const io = IO.init({ signer }); - const res = await io - .transfer({ - target: 'QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ', - qty: 1, - }) - .catch((e) => e); - // if it is a WriteInteractionError, it means the transaction was signed contract threw an error - assert(res instanceof WriteInteractionError); + + assert(io); } }); it('Should be able to sign on ANTs with all ContractSigner types', async () => { @@ -314,14 +307,8 @@ describe('Signing', async () => { processId: 'aWI_dq1JH7facsulLuas1X3l5dkKuWtixcZDYMw9mpg', signer, }); - const res = await ant - .transfer({ - target: 'aWI_dq1JH7facsulLuas1X3l5dkKuWtixcZDYMw9mpg', - qty: 1, - }) - .catch((e) => e); - // if it is a WriteInteractionError, it means the transaction was signed contract threw an error - assert(res instanceof WriteInteractionError); + + assert(ant); } }); @@ -330,10 +317,7 @@ describe('Signing', async () => { const registry = ANTRegistry.init({ signer, }); - const res = await registry.register({ - processId: ''.padEnd(43, '1'), - }); - assert(res.id); + assert(registry); } }); }); diff --git a/tests/e2e/esm/index.test.js b/tests/e2e/esm/index.test.js index d4d934cf..bde4ce7b 100644 --- a/tests/e2e/esm/index.test.js +++ b/tests/e2e/esm/index.test.js @@ -3,7 +3,6 @@ import { ANTRegistry, ArweaveSigner, IO, - WriteInteractionError, createAoSigner, ioDevnetProcessId, } from '@ar.io/sdk'; @@ -299,14 +298,8 @@ describe('Signing', async () => { it('Should be able to sign on the IO contract with all ContractSigner types', async () => { for (const signer of signers) { const io = IO.init({ signer }); - const res = await io - .transfer({ - target: 'QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ', - qty: 1, - }) - .catch((e) => e); - // if it is a WriteInteractionError, it means the transaction was signed contract threw an error - assert(res instanceof WriteInteractionError); + + assert(io); } }); it('Should be able to sign on ANTs with all ContractSigner types', async () => { @@ -315,14 +308,8 @@ describe('Signing', async () => { processId: 'aWI_dq1JH7facsulLuas1X3l5dkKuWtixcZDYMw9mpg', signer, }); - const res = await ant - .transfer({ - target: 'aWI_dq1JH7facsulLuas1X3l5dkKuWtixcZDYMw9mpg', - qty: 1, - }) - .catch((e) => e); - // if it is a WriteInteractionError, it means the transaction was signed contract threw an error - assert(res instanceof WriteInteractionError); + + assert(ant); } }); @@ -331,10 +318,7 @@ describe('Signing', async () => { const registry = ANTRegistry.init({ signer, }); - const res = await registry.register({ - processId: ''.padEnd(43, '1'), - }); - assert(res.id); + assert(registry); } }); }); From 0d7f210ac3ab44a1c7ea296936917e5297878e48 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Mon, 19 Aug 2024 14:18:13 -0600 Subject: [PATCH 07/23] fix(signer): add typeguard util for aoSigner --- package.json | 3 ++- src/utils/ao.ts | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ce9c65bc..252a2dd1 100644 --- a/package.json +++ b/package.json @@ -127,7 +127,8 @@ "axios-retry": "^4.3.0", "eventemitter3": "^5.0.1", "plimit-lit": "^3.0.1", - "winston": "^3.13.0" + "winston": "^3.13.0", + "zod": "^3.23.8" }, "lint-staged": { "**/*.{ts,js,mjs,cjs,md,json}": [ diff --git a/src/utils/ao.ts b/src/utils/ao.ts index 6dc6765a..639ff9fe 100644 --- a/src/utils/ao.ts +++ b/src/utils/ao.ts @@ -16,6 +16,7 @@ */ import { connect, createDataItemSigner } from '@permaweb/aoconnect'; import { createData } from 'arbundles'; +import { z } from 'zod'; import { defaultArweave } from '../common/arweave.js'; import { AOProcess } from '../common/index.js'; @@ -157,8 +158,40 @@ export async function evolveANT({ return id; } +export function isAoSigner(value: unknown): value is AoSigner { + const TagSchema = z.object({ + name: z.string(), + value: z.union([z.string(), z.number()]), + }); + + const AoSignerSchema = z + .function() + .args( + z.object({ + data: z.union([z.string(), z.instanceof(Buffer)]), + tags: z.array(TagSchema).optional(), + target: z.string().optional(), + anchor: z.string().optional(), + }), + ) + .returns( + z.promise( + z.object({ + id: z.string(), + raw: z.instanceof(ArrayBuffer), + }), + ), + ); + try { + AoSignerSchema.parse(value); + return true; + } catch { + return false; + } +} + export function createAoSigner(signer: ContractSigner): AoSigner { - if (typeof signer == 'function') { + if (isAoSigner(signer)) { return signer; } From 27a5dc25cd6bbe75736187280d3f511235dfa0b0 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Mon, 19 Aug 2024 16:07:24 -0600 Subject: [PATCH 08/23] fix(tests): use test-wallet fixture in tests instead of generating anew each time --- tests/e2e/cjs/index.test.js | 23 ++++++++------- tests/e2e/esm/index.test.js | 24 +++++++++------- tests/e2e/test-wallet.json | 11 +++++++ tests/utils.ts | 57 ------------------------------------- 4 files changed, 37 insertions(+), 78 deletions(-) create mode 100644 tests/e2e/test-wallet.json delete mode 100644 tests/utils.ts diff --git a/tests/e2e/cjs/index.test.js b/tests/e2e/cjs/index.test.js index 4451774b..3ecc8424 100644 --- a/tests/e2e/cjs/index.test.js +++ b/tests/e2e/cjs/index.test.js @@ -11,10 +11,14 @@ const { ANT, createAoSigner, ArweaveSigner, + IOWriteable, + AoANTWriteable, + AoANTRegistryWriteable, } = require('@ar.io/sdk'); -const Arweave = require('arweave'); -const arweave = Arweave.init({}); +const testWalletJSON = require('../test-wallet.json'); +const testWallet = JSON.parse(testWalletJSON); + const io = IO.init({ processId: ioDevnetProcessId, }); @@ -288,17 +292,16 @@ describe('ANTRegistry', async () => { }); describe('Signing', async () => { - let signers = []; - before(async () => { - const jwk = await arweave.wallets.generate(); - signers = [new ArweaveSigner(jwk), createAoSigner(new ArweaveSigner(jwk))]; - }); + const signers = [ + new ArweaveSigner(testWallet), + createAoSigner(new ArweaveSigner(testWallet)), + ]; it('Should be able to sign on the IO contract with all ContractSigner types', async () => { for (const signer of signers) { const io = IO.init({ signer }); - assert(io); + assert(io instanceof IOWriteable); } }); it('Should be able to sign on ANTs with all ContractSigner types', async () => { @@ -308,7 +311,7 @@ describe('Signing', async () => { signer, }); - assert(ant); + assert(ant instanceof AoANTWriteable); } }); @@ -317,7 +320,7 @@ describe('Signing', async () => { const registry = ANTRegistry.init({ signer, }); - assert(registry); + assert(registry instanceof AoANTRegistryWriteable); } }); }); diff --git a/tests/e2e/esm/index.test.js b/tests/e2e/esm/index.test.js index bde4ce7b..4e9c6460 100644 --- a/tests/e2e/esm/index.test.js +++ b/tests/e2e/esm/index.test.js @@ -6,9 +6,12 @@ import { createAoSigner, ioDevnetProcessId, } from '@ar.io/sdk'; -import Arweave from 'arweave'; import { strict as assert } from 'node:assert'; -import { before, describe, it } from 'node:test'; +import { describe, it } from 'node:test'; + +import testWalletJSON from '../test-wallet.json'; + +const testWallet = JSON.parse(testWalletJSON); /** * Ensure that npm link has been ran prior to running these tests @@ -18,7 +21,7 @@ import { before, describe, it } from 'node:test'; const io = IO.init({ processId: ioDevnetProcessId, }); -const arweave = Arweave.init({}); + describe('IO', async () => { it('should be able to get the process information', async () => { const epoch = await io.getInfo(); @@ -289,17 +292,16 @@ describe('ANTRegistry', async () => { }); describe('Signing', async () => { - let signers = []; - before(async () => { - const jwk = await arweave.wallets.generate(); - signers = [new ArweaveSigner(jwk), createAoSigner(new ArweaveSigner(jwk))]; - }); + const signers = [ + new ArweaveSigner(testWallet), + createAoSigner(new ArweaveSigner(testWallet)), + ]; it('Should be able to sign on the IO contract with all ContractSigner types', async () => { for (const signer of signers) { const io = IO.init({ signer }); - assert(io); + assert(io instanceof IOWriteable); } }); it('Should be able to sign on ANTs with all ContractSigner types', async () => { @@ -309,7 +311,7 @@ describe('Signing', async () => { signer, }); - assert(ant); + assert(ant instanceof AoANTWriteable); } }); @@ -318,7 +320,7 @@ describe('Signing', async () => { const registry = ANTRegistry.init({ signer, }); - assert(registry); + assert(registry instanceof AoANTRegistryWriteable); } }); }); diff --git a/tests/e2e/test-wallet.json b/tests/e2e/test-wallet.json new file mode 100644 index 00000000..c1243469 --- /dev/null +++ b/tests/e2e/test-wallet.json @@ -0,0 +1,11 @@ +{ + "kty": "RSA", + "n": "s-Whr7NsoyY0x5nFZDAXIzLymEQvK-9ZW_-cH7TKfnxJn24Z9KndUl8fuE_7QRP2VUmlcTM-YjeS7maw68CZrk_2VKbxnN1Gcvj1SqfuvdnZ0aDgD-FQVEpnOWtAToAEZrV-mwiXBHGEIr8_ntmw4TZJwXmNjVUEhA4rVekKDGHD2k-mooc1wliNG-WMS5e-6Qbor_WNbI0G7HI1WJ46qgMZr4aK2OV1WkwL7Z-5xtSUKLJJJ9Uw1BJvjxaOPo3Eu6zJGxnTGMt3xKSD4ZnJV5H16W9609OTURLezVoIQ8VxmF5W_2sawueAp3g2x4dAwaBIhrfQVjn-Fq7bpTKFg1tlfuzIruh0KUXqftYfWpD3qJxHZLnUJl90oCLUw5oDs7Fvx23TToy92ouZdeMhHjIkNRDBGMAuOzrE5qz-f973LDR0Hz88wzBZ7mZDvSA_UEPKVoRZ99ON_w79BU-Pw1XlvYRAAEDrC1zWojVxMGCqRaWR4OMbQE5eWGTE-5tlpb2zuc970ihdwEmS54V6SLzx9mVAy6WfgWMLxYyqjz30538D8ZbUn8mGk4-WVoaXgncPU2F9bVs3bNaTuAWZZxAPZ7E139NTIrW-MbH_nTgch09vq7giI8XEWryWzRSGmZl-IoRN4Nnn2FyoX8nuk7QyZC2j-6y5j4jWXvkJABE", + "e": "AQAB", + "d": "PE0s9YhfUhDsgDu7Puof11yslP3GEiQZAA2ed8JSXjOrOhXd_XUzCvl32IB26EmYuN4G5vsWXjXiuqcRhvT4jsWe_KE5PCuwAboR_wRrspfju7EBalFMa_TExSp-U9H1p7gOyEkI1iR29m7FFKpD8DoSXxgvqsBk0x8sx49mHuBmljc81B4elxa3tjIr5Orow5PdS54z2b8sIvXli97-Kx7-7SdcQ3gm7i2vkeeIjm2TfFDG1ONRisTjQEN_StiaqY4xmzP83sLVUsUSr_ys0P3MQINt2LODHhoFNTCItK7qdPiqkNOGFO8k4P4a3qcnvb_Mj9vtqfmmglP6rFVTCzPHWSSZi2HOZlPGQc53Zx33ZS4moNNTo63hwsa4VKqWTNvZoZF9MafuBQYn_GovkaJkKB542VnhGoT-NsA3HISDhffT6U0q-vWqUOIZmgf8Ut3ghS9XiFUjnBn_EdDix_ryxnmrwpWwUk4q15gDCJ-Ych05uzUbtNPk0LdLRPofpcOJ0uPSv9-5r6ouYJoR92ODxXFhcWGq6GFVT9s9ETNMehw8A54J72n5XfnePF8D5qPe4YZw8DgcIAzmrr42jmNI5YSt3lBVfOoe8meYc_a77t0WmTsIia9nnBpgP4dl12s6EAentsFZfvLRU3cvCy1gsk2En3vPMdiRXJUzrkE", + "p": "9nbx4FZClWKyHFygc3djqRyKff44KD7KFMgOSEKbxvioop1lynSLjTsRMMzT31_htXq0COSLBrUmbzoI5iO8GUmU9F_ht1j4sbwcsYmyyLdNsURWZwYCb00LPDyqvqn87J5IuTifJ4CZB8e1EE3H8HrbnB-uKZJGiEhaIiCCs1-t0sGKY9QtuE2Ovly9RGkj6fi9yqIZyF6ySHopWtLQ90GtVh8El4eIL-PeGPBvahbffUNOwEpfc0QIjOBkrHT8wdlXuU3rWFSi7aKd2mVj6QFiq_pF-Z8ESc0NAQlLIY0kbKKv29blcpY9sgKBpTAYMYRj93AdQstNoddRZ5fdyw", + "q": "utth1reY8OFEDIHe48K_pyyPmoMsRCdFhtXEqBljRNaQKQk6ijajPco7ycYTucef1_TlIBbSfm6WropbRyi9e9ebaA0kWNqPYaef9vtYEwdq3f9YfrHXaVXSGmfWXw-fp81QGm6IDRN3YlRn-_6rWB7MynkvYdJSh7K_GRw39TUkcWIrKNbFmPi1InKi-i9VDTQJL1REkQmAduPScjRzsNGmM3Ngqt3PNfejhronSICSGrwbUJ9-C5sauGAIJo090KS2f8p15ljGQ_X0WT9JWnsZ59K8nL5cLOUVZpKc5U0AoS_HqR7O7BIFLJo8BEWiJd_Jmg-Ln6UCOzxWBZleEw", + "dp": "47PYm66WLXXVoCZjhsoSpTbdLLImJ-h6wuBhcZk4Wod5JWPNm1I5a-3aX_-c746h9Qy8MEsVtsi-DZzMg_MX4TT-DRhYbRAiE_L7f3r8Vjwj51Z_jQccUMAZVTmndieOqP1DqvwI7nH88BctzTZPNnoLUx5hxb6Cs35E56qplhcbfM-aj8iDxPbCnlUH96A7sfpBPmis8VWr2RIkCukibo2bGynlECoDRFt94gSgqp8fM5dvtm__53o_fAgEeuBKdL3cMjMu75iiPnIy7Icn2ymQg9rhs1GaoKR1EzQG2aSQtl1HpA_SRB9SOJfgN0FL2NO7l-tY3VD_FDrd1puUKQ", + "dq": "t3YSl9jnpwnl4Ena59EcjyznShOkcL4GO57DWTCkEMCCBmhzO6TtngtjrHZ4g52GSWi_VkRSI6S8-V4KxNExSdilUwIkP8FHqeAE5WBeV0CfIpxE7Q_7qgaDJT3ycp9KaFzjWzBPEFeejcLF3dtrrDeBZwKZDPiN44ISsrrMDktBHrn-GjjVBZ6badkYP4Adh7shkYCxWZ30rcZ9p3fsZx1Qi4-qx9jES_56Zht72mmyCeHLB9uwzABbuc8_8WoX2TT_onTMUX-0GqHwaXgDs3zOMJjuaw9UPRgnbPBib5itF5Vr-ZawH4SJ5AMDDka4L2uL62F7-yDuEe7pntG4VQ", + "qi": "PYzb643Ko2kHMwP7z44xAoldwzvKfKy-5rKjifzpJ-oX3Nsec99goV5JfDXDDmZhJmfqX93L9znEIFmA17dwzwJ6Gho2ReqDacze-SQNyKywuE77b5XXvCx-lVx1DWS0DTR7ykUkf8K6Pl6JKHNpc0FAeK8olk0PdqVf-TvXE8NjHc1vDsxwK2woiUkizyd-Xn054U1Abe_sy7_gwFFCNo7nUFJxk6AG4v4yinbxn8dAmAATh37sPnB3U4Ac4yNfFYSqf6HZzCMyt2UlPZsLKLZP2OtHoYaHWJWoZjfyChbaEleXTvaDIGzrgrnsOH5fsCvGie1zZAs1X7DhvCiTTQ" +} diff --git a/tests/utils.ts b/tests/utils.ts deleted file mode 100644 index 75b17487..00000000 --- a/tests/utils.ts +++ /dev/null @@ -1,57 +0,0 @@ -import Arweave from 'arweave'; -import { JWKInterface } from 'arweave/node/lib/wallet'; -import * as fs from 'fs'; -import path from 'path'; - -const oneYearSeconds = 60 * 60 * 24 * 365; - -export async function createLocalWallet( - arweave: Arweave, - amount = 10_000_000_000_000, -): Promise<{ wallet: JWKInterface; address: string }> { - // ~~ Generate wallet and add funds ~~ - const wallet = await arweave.wallets.generate(); - const address = await arweave.wallets.jwkToAddress(wallet); - // mint some tokens - await arweave.api.get(`/mint/${address}/${amount}`); - - const walletDir = path.join(__dirname, './wallets'); - const walletPath = path.join(walletDir, `${address}.json`); - // save it to local directory - if (!fs.existsSync(walletPath)) { - fs.writeFileSync(walletPath, JSON.stringify(wallet)); - } - - return { - wallet, - address, - }; -} - -export function removeDirectories() { - ['./wallets', './contracts'].forEach((dir) => { - const dirPath = path.join(__dirname, dir); - if (fs.existsSync(dirPath)) { - fs.rmSync(dirPath, { recursive: true }); - } - }); -} - -export function createDirectories() { - ['./wallets', './contracts'].forEach((dir) => { - const dirPath = path.join(__dirname, dir); - if (!fs.existsSync(dirPath)) { - fs.mkdirSync(dirPath); - } - }); -} - -export function mineBlocks({ - arweave, - blocks = 1, -}: { - arweave: Arweave; - blocks?: number; -}) { - return arweave.api.get('/mine/' + blocks); -} From 1872a262b654d72c779c2607ed454c5ae8271e87 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Tue, 20 Aug 2024 07:59:20 -0600 Subject: [PATCH 09/23] fix(tests): reconfigure test structure --- tests/e2e/cjs/index.test.js | 47 ++++++++++++++++++---------------- tests/e2e/esm/index.test.js | 50 +++++++++++++++++++++---------------- 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/tests/e2e/cjs/index.test.js b/tests/e2e/cjs/index.test.js index 3ecc8424..b740c656 100644 --- a/tests/e2e/cjs/index.test.js +++ b/tests/e2e/cjs/index.test.js @@ -1,5 +1,6 @@ const { describe, it, before } = require('node:test'); const assert = require('node:assert/strict'); +const fs = require('node:fs'); /** * Ensure that npm link has been ran prior to running these tests * (simply running npm run test:integration will ensure npm link is ran) @@ -16,8 +17,14 @@ const { AoANTRegistryWriteable, } = require('@ar.io/sdk'); -const testWalletJSON = require('../test-wallet.json'); +const testWalletJSON = fs.readFileSync('../test-wallet.json', { + encoding: 'utf-8', +}); const testWallet = JSON.parse(testWalletJSON); +const signers = [ + new ArweaveSigner(testWallet), + createAoSigner(new ArweaveSigner(testWallet)), +]; const io = IO.init({ processId: ioDevnetProcessId, @@ -278,6 +285,14 @@ describe('IO', async () => { }); assert.ok(tokenCost); }); + + it('should be able to create IOWriteable with valid signers', async () => { + for (const signer of signers) { + const io = IO.init({ signer }); + + assert(io instanceof IOWriteable); + } + }); }); describe('ANTRegistry', async () => { @@ -289,22 +304,19 @@ describe('ANTRegistry', async () => { assert(Array.isArray(affiliatedAnts.Owned)); assert(Array.isArray(affiliatedAnts.Controlled)); }); -}); -describe('Signing', async () => { - const signers = [ - new ArweaveSigner(testWallet), - createAoSigner(new ArweaveSigner(testWallet)), - ]; - - it('Should be able to sign on the IO contract with all ContractSigner types', async () => { + it('should be able to create AoANTRegistryWriteable with valid signers', async () => { for (const signer of signers) { - const io = IO.init({ signer }); - - assert(io instanceof IOWriteable); + const registry = ANTRegistry.init({ + signer, + }); + assert(registry instanceof AoANTRegistryWriteable); } }); - it('Should be able to sign on ANTs with all ContractSigner types', async () => { +}); + +describe('ANT', async () => { + it('should be able to create ANTWriteable with valid signers', async () => { for (const signer of signers) { const ant = ANT.init({ processId: 'aWI_dq1JH7facsulLuas1X3l5dkKuWtixcZDYMw9mpg', @@ -314,13 +326,4 @@ describe('Signing', async () => { assert(ant instanceof AoANTWriteable); } }); - - it('Should be able to sign on ANTRegistry with all ContractSigner types', async () => { - for (const signer of signers) { - const registry = ANTRegistry.init({ - signer, - }); - assert(registry instanceof AoANTRegistryWriteable); - } - }); }); diff --git a/tests/e2e/esm/index.test.js b/tests/e2e/esm/index.test.js index 4e9c6460..704f3a52 100644 --- a/tests/e2e/esm/index.test.js +++ b/tests/e2e/esm/index.test.js @@ -1,17 +1,27 @@ import { ANT, ANTRegistry, + AoANTRegistryWriteable, + AoANTWriteable, ArweaveSigner, IO, + IOWriteable, createAoSigner, ioDevnetProcessId, } from '@ar.io/sdk'; import { strict as assert } from 'node:assert'; +import fs from 'node:fs'; import { describe, it } from 'node:test'; -import testWalletJSON from '../test-wallet.json'; +const testWalletJSON = fs.readFileSync('../test-wallet.json', { + encoding: 'utf-8', +}); const testWallet = JSON.parse(testWalletJSON); +const signers = [ + new ArweaveSigner(testWallet), + createAoSigner(new ArweaveSigner(testWallet)), +]; /** * Ensure that npm link has been ran prior to running these tests @@ -278,6 +288,14 @@ describe('IO', async () => { }); assert.ok(tokenCost); }); + + it('should be able to create IOWriteable with valid signers', async () => { + for (const signer of signers) { + const io = IO.init({ signer }); + + assert(io instanceof IOWriteable); + } + }); }); describe('ANTRegistry', async () => { @@ -289,22 +307,19 @@ describe('ANTRegistry', async () => { assert(Array.isArray(affiliatedAnts.Owned)); assert(Array.isArray(affiliatedAnts.Controlled)); }); -}); -describe('Signing', async () => { - const signers = [ - new ArweaveSigner(testWallet), - createAoSigner(new ArweaveSigner(testWallet)), - ]; - - it('Should be able to sign on the IO contract with all ContractSigner types', async () => { + it('should be able to create AoANTRegistryWriteable with valid signers', async () => { for (const signer of signers) { - const io = IO.init({ signer }); - - assert(io instanceof IOWriteable); + const registry = ANTRegistry.init({ + signer, + }); + assert(registry instanceof AoANTRegistryWriteable); } }); - it('Should be able to sign on ANTs with all ContractSigner types', async () => { +}); + +describe('ANT', async () => { + it('should be able to create ANTWriteable with valid signers', async () => { for (const signer of signers) { const ant = ANT.init({ processId: 'aWI_dq1JH7facsulLuas1X3l5dkKuWtixcZDYMw9mpg', @@ -314,13 +329,4 @@ describe('Signing', async () => { assert(ant instanceof AoANTWriteable); } }); - - it('Should be able to sign on ANTRegistry with all ContractSigner types', async () => { - for (const signer of signers) { - const registry = ANTRegistry.init({ - signer, - }); - assert(registry instanceof AoANTRegistryWriteable); - } - }); }); From 968c30e9b3851c0eed1bb7e152e78835d558243b Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Tue, 20 Aug 2024 10:22:21 -0600 Subject: [PATCH 10/23] feat(ant id): update lua ant id to latest --- src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index dd98981a..f4dfec89 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -41,6 +41,6 @@ export const IO_TESTNET_PROCESS_ID = export const ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc'; export const MIO_PER_IO = 1_000_000; export const AOS_MODULE_ID = 'cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk'; -export const ANT_LUA_ID = 'Flwio4Lr08g6s6uim6lEJNnVGD9ylvz0_aafvpiL8FI'; +export const ANT_LUA_ID = 'BVZZ0_ME8uq3zChN6bA6WsPmFhVpGDJ7Rb7l4qoGIDM'; export const DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA'; From 4125c73de02113f63c1e202944e64b1c072e16dc Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 20 Aug 2024 20:51:34 +0000 Subject: [PATCH 11/23] chore(release): 2.1.0-alpha.12 [skip ci] # [2.1.0-alpha.12](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0-alpha.11...v2.1.0-alpha.12) (2024-08-20) ### Bug Fixes * **signer:** add typeguard util for aoSigner ([0d7f210](https://github.com/ar-io/ar-io-sdk/commit/0d7f210ac3ab44a1c7ea296936917e5297878e48)) * **signing:** add aosigner to contract signer ([3b0495a](https://github.com/ar-io/ar-io-sdk/commit/3b0495a3ca4420c61cf4f72c7eb451777cbaf16d)) * **tests:** dont send messages to ao in e2e tests ([e7108da](https://github.com/ar-io/ar-io-sdk/commit/e7108dafb7602e29833b0120c91cff73b022d31f)) * **tests:** reconfigure test structure ([1872a26](https://github.com/ar-io/ar-io-sdk/commit/1872a262b654d72c779c2607ed454c5ae8271e87)) * **tests:** use test-wallet fixture in tests instead of generating anew each time ([27a5dc2](https://github.com/ar-io/ar-io-sdk/commit/27a5dc25cd6bbe75736187280d3f511235dfa0b0)) --- CHANGELOG.md | 11 +++++++++++ package.json | 2 +- src/version.ts | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20494271..fe9b6ec1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# [2.1.0-alpha.12](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0-alpha.11...v2.1.0-alpha.12) (2024-08-20) + + +### Bug Fixes + +* **signer:** add typeguard util for aoSigner ([0d7f210](https://github.com/ar-io/ar-io-sdk/commit/0d7f210ac3ab44a1c7ea296936917e5297878e48)) +* **signing:** add aosigner to contract signer ([3b0495a](https://github.com/ar-io/ar-io-sdk/commit/3b0495a3ca4420c61cf4f72c7eb451777cbaf16d)) +* **tests:** dont send messages to ao in e2e tests ([e7108da](https://github.com/ar-io/ar-io-sdk/commit/e7108dafb7602e29833b0120c91cff73b022d31f)) +* **tests:** reconfigure test structure ([1872a26](https://github.com/ar-io/ar-io-sdk/commit/1872a262b654d72c779c2607ed454c5ae8271e87)) +* **tests:** use test-wallet fixture in tests instead of generating anew each time ([27a5dc2](https://github.com/ar-io/ar-io-sdk/commit/27a5dc25cd6bbe75736187280d3f511235dfa0b0)) + # [2.1.0-alpha.11](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0-alpha.10...v2.1.0-alpha.11) (2024-08-08) diff --git a/package.json b/package.json index 252a2dd1..0ce1cf37 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ar.io/sdk", - "version": "2.1.0-alpha.11", + "version": "2.1.0-alpha.12", "repository": { "type": "git", "url": "git+https://github.com/ar-io/ar-io-sdk.git" diff --git a/src/version.ts b/src/version.ts index f34308a0..f36e9a08 100644 --- a/src/version.ts +++ b/src/version.ts @@ -17,4 +17,4 @@ // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH -export const version = '2.1.0-alpha.11'; +export const version = '2.1.0-alpha.12'; From 0de8478a0f557b196149797e8d8a5cc873725166 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 21 Aug 2024 16:39:43 +0000 Subject: [PATCH 12/23] chore(release): 2.1.0-alpha.13 [skip ci] # [2.1.0-alpha.13](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0-alpha.12...v2.1.0-alpha.13) (2024-08-21) ### Features * **ant id:** update lua ant id to latest ([968c30e](https://github.com/ar-io/ar-io-sdk/commit/968c30e9b3851c0eed1bb7e152e78835d558243b)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- src/version.ts | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe9b6ec1..9186506a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [2.1.0-alpha.13](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0-alpha.12...v2.1.0-alpha.13) (2024-08-21) + + +### Features + +* **ant id:** update lua ant id to latest ([968c30e](https://github.com/ar-io/ar-io-sdk/commit/968c30e9b3851c0eed1bb7e152e78835d558243b)) + # [2.1.0-alpha.12](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0-alpha.11...v2.1.0-alpha.12) (2024-08-20) diff --git a/package.json b/package.json index 0ce1cf37..cf56ffea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ar.io/sdk", - "version": "2.1.0-alpha.12", + "version": "2.1.0-alpha.13", "repository": { "type": "git", "url": "git+https://github.com/ar-io/ar-io-sdk.git" diff --git a/src/version.ts b/src/version.ts index f36e9a08..c2517e5c 100644 --- a/src/version.ts +++ b/src/version.ts @@ -17,4 +17,4 @@ // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH -export const version = '2.1.0-alpha.12'; +export const version = '2.1.0-alpha.13'; From 114164c84fb3f48be4b298ad1d8180c6f140bfa0 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 22 Aug 2024 02:33:26 +0000 Subject: [PATCH 13/23] chore(release): 2.2.0-alpha.1 [skip ci] # [2.2.0-alpha.1](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0...v2.2.0-alpha.1) (2024-08-22) ### Bug Fixes * **register:** update spawn ant to register at end of spawn ([4320c80](https://github.com/ar-io/ar-io-sdk/commit/4320c803bec96eedf4fe4bd5456a5eaa4ac9ae88)) * **signer:** add typeguard util for aoSigner ([0d7f210](https://github.com/ar-io/ar-io-sdk/commit/0d7f210ac3ab44a1c7ea296936917e5297878e48)) * **signing:** add aosigner to contract signer ([3b0495a](https://github.com/ar-io/ar-io-sdk/commit/3b0495a3ca4420c61cf4f72c7eb451777cbaf16d)) * **tests:** dont send messages to ao in e2e tests ([e7108da](https://github.com/ar-io/ar-io-sdk/commit/e7108dafb7602e29833b0120c91cff73b022d31f)) * **tests:** reconfigure test structure ([1872a26](https://github.com/ar-io/ar-io-sdk/commit/1872a262b654d72c779c2607ed454c5ae8271e87)) * **tests:** use test-wallet fixture in tests instead of generating anew each time ([27a5dc2](https://github.com/ar-io/ar-io-sdk/commit/27a5dc25cd6bbe75736187280d3f511235dfa0b0)) ### Features * **ant id:** update lua ant id to latest ([968c30e](https://github.com/ar-io/ar-io-sdk/commit/968c30e9b3851c0eed1bb7e152e78835d558243b)) --- CHANGELOG.md | 17 +++++++++++++++++ package.json | 2 +- src/version.ts | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec2d98f9..73b4b41b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +# [2.2.0-alpha.1](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0...v2.2.0-alpha.1) (2024-08-22) + + +### Bug Fixes + +* **register:** update spawn ant to register at end of spawn ([4320c80](https://github.com/ar-io/ar-io-sdk/commit/4320c803bec96eedf4fe4bd5456a5eaa4ac9ae88)) +* **signer:** add typeguard util for aoSigner ([0d7f210](https://github.com/ar-io/ar-io-sdk/commit/0d7f210ac3ab44a1c7ea296936917e5297878e48)) +* **signing:** add aosigner to contract signer ([3b0495a](https://github.com/ar-io/ar-io-sdk/commit/3b0495a3ca4420c61cf4f72c7eb451777cbaf16d)) +* **tests:** dont send messages to ao in e2e tests ([e7108da](https://github.com/ar-io/ar-io-sdk/commit/e7108dafb7602e29833b0120c91cff73b022d31f)) +* **tests:** reconfigure test structure ([1872a26](https://github.com/ar-io/ar-io-sdk/commit/1872a262b654d72c779c2607ed454c5ae8271e87)) +* **tests:** use test-wallet fixture in tests instead of generating anew each time ([27a5dc2](https://github.com/ar-io/ar-io-sdk/commit/27a5dc25cd6bbe75736187280d3f511235dfa0b0)) + + +### Features + +* **ant id:** update lua ant id to latest ([968c30e](https://github.com/ar-io/ar-io-sdk/commit/968c30e9b3851c0eed1bb7e152e78835d558243b)) + # [2.1.0](https://github.com/ar-io/ar-io-sdk/compare/v2.0.2...v2.1.0) (2024-08-07) diff --git a/package.json b/package.json index cf56ffea..3a07e74b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ar.io/sdk", - "version": "2.1.0-alpha.13", + "version": "2.2.0-alpha.1", "repository": { "type": "git", "url": "git+https://github.com/ar-io/ar-io-sdk.git" diff --git a/src/version.ts b/src/version.ts index c2517e5c..1bfa62ac 100644 --- a/src/version.ts +++ b/src/version.ts @@ -17,4 +17,4 @@ // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH -export const version = '2.1.0-alpha.13'; +export const version = '2.2.0-alpha.1'; From c6f457f88f7b17af615ffacc593cc01b77230257 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Mon, 26 Aug 2024 09:20:53 -0600 Subject: [PATCH 14/23] feat(util): add AoAntState typeguard util --- src/utils/ao.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/utils/ao.ts b/src/utils/ao.ts index 639ff9fe..60a09727 100644 --- a/src/utils/ao.ts +++ b/src/utils/ao.ts @@ -28,6 +28,7 @@ import { } from '../constants.js'; import { AoANTRecord, + AoANTState, AoClient, AoSigner, ContractSigner, @@ -218,3 +219,34 @@ export function createAoSigner(signer: ContractSigner): AoSigner { return aoSigner; } + +/** + * @param state + * @returns {boolean} + * @throws {z.ZodError} if the state object does not match the expected schema + */ +export function isAoANTState(state: object): state is AoANTState { + // using passThrough to require the minimum fields and allow others (eg TotalSupply, Logo, etc) + const AntStateSchema = z + .object({ + Name: z.string(), + Ticker: z.string(), + Owner: z.string(), + Controllers: z.array(z.string()), + Records: z.record( + z.string(), + z + .object({ + transactionId: z.string(), + ttlSeconds: z.number(), + }) + .passthrough(), + ), + Balances: z.record(z.string(), z.number()), + }) + .passthrough(); + + AntStateSchema.parse(state); + + return true; +} From ea285e5807c17545fd06e980ffcd81357b8881e6 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Mon, 26 Aug 2024 09:39:56 -0600 Subject: [PATCH 15/23] chore(tests): test ant typeguard --- tests/unit/ant.test.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/unit/ant.test.ts diff --git a/tests/unit/ant.test.ts b/tests/unit/ant.test.ts new file mode 100644 index 00000000..9984a529 --- /dev/null +++ b/tests/unit/ant.test.ts @@ -0,0 +1,37 @@ +import assert from 'node:assert'; + +import { isAoANTState } from '../../src/utils/ao'; + +const testAoANTState = { + Name: 'TestToken', + Ticker: 'TST', + Denomination: 1, + Owner: ''.padEnd(43, '1'), + Controllers: [''.padEnd(43, '2')], + Records: { + record1: { + transactionId: ''.padEnd(43, '1'), + ttlSeconds: 3600, + }, + }, + Balances: { + [''.padEnd(43, '1')]: 1, + }, + Logo: ''.padEnd(43, '1'), + TotalSupply: 0, + Initialized: true, +}; +describe('ANT', () => { + it('should validate accurate ANT state', () => { + const res = isAoANTState(testAoANTState); + assert.strictEqual(res, true); + }); + + it('should invalidate inaccurate ANT state', () => { + try { + isAoANTState({ ...testAoANTState, Name: 1 }); + } catch (error) { + assert(error instanceof Error); + } + }); +}); From 4b851c5bd904f66bd88efc67cdc239a1300c7ecf Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Mon, 26 Aug 2024 12:31:41 -0600 Subject: [PATCH 16/23] fix(typeguard): return true or false in typeguard and log the error --- src/utils/ao.ts | 52 +++++++++++++++++++++++------------------- tests/unit/ant.test.ts | 7 ++---- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/utils/ao.ts b/src/utils/ao.ts index 60a09727..44dc268a 100644 --- a/src/utils/ao.ts +++ b/src/utils/ao.ts @@ -19,7 +19,7 @@ import { createData } from 'arbundles'; import { z } from 'zod'; import { defaultArweave } from '../common/arweave.js'; -import { AOProcess } from '../common/index.js'; +import { AOProcess, Logger } from '../common/index.js'; import { ANT_LUA_ID, ANT_REGISTRY_ID, @@ -220,33 +220,39 @@ export function createAoSigner(signer: ContractSigner): AoSigner { return aoSigner; } +// using passThrough to require the minimum fields and allow others (eg TotalSupply, Logo, etc) +export const AntStateSchema = z + .object({ + Name: z.string(), + Ticker: z.string(), + Owner: z.string(), + Controllers: z.array(z.string()), + Records: z.record( + z.string(), + z + .object({ + transactionId: z.string(), + ttlSeconds: z.number(), + }) + .passthrough(), + ), + Balances: z.record(z.string(), z.number()), + }) + .passthrough(); + /** * @param state * @returns {boolean} * @throws {z.ZodError} if the state object does not match the expected schema */ export function isAoANTState(state: object): state is AoANTState { - // using passThrough to require the minimum fields and allow others (eg TotalSupply, Logo, etc) - const AntStateSchema = z - .object({ - Name: z.string(), - Ticker: z.string(), - Owner: z.string(), - Controllers: z.array(z.string()), - Records: z.record( - z.string(), - z - .object({ - transactionId: z.string(), - ttlSeconds: z.number(), - }) - .passthrough(), - ), - Balances: z.record(z.string(), z.number()), - }) - .passthrough(); - - AntStateSchema.parse(state); + try { + AntStateSchema.parse(state); - return true; + return true; + } catch (error) { + // this allows us to see the path of the error in the object as well as the expected schema on invalid fields + Logger.default.error(error.issues); + return false; + } } diff --git a/tests/unit/ant.test.ts b/tests/unit/ant.test.ts index 9984a529..429d8644 100644 --- a/tests/unit/ant.test.ts +++ b/tests/unit/ant.test.ts @@ -28,10 +28,7 @@ describe('ANT', () => { }); it('should invalidate inaccurate ANT state', () => { - try { - isAoANTState({ ...testAoANTState, Name: 1 }); - } catch (error) { - assert(error instanceof Error); - } + const res = isAoANTState({ ...testAoANTState, Name: 1 }); + assert.strictEqual(res, false); }); }); From 5aedf5077a68faec8d86281a401ab2f4d6daf142 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Tue, 27 Aug 2024 06:53:11 -0600 Subject: [PATCH 17/23] fix(types): update types for epoch distributions The new snapshots set eligible rewards at the beginning of the epoch. Distributions are added after the epoch ends --- src/io.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/io.ts b/src/io.ts index 47df5fca..d57f0126 100644 --- a/src/io.ts +++ b/src/io.ts @@ -96,11 +96,26 @@ export type AoVaultData = { endTimestamp: Timestamp; }; +export type AoEpochDistributionRewards = { + eligible: Record< + WalletAddress, + { + delegateRewards: Record; + operatorReward: number; + } + >; + // TODO: we could create a new type for this + distributed?: Record; +}; + export type AoEpochDistributionData = { - rewards: Record; - distributedTimestamp: Timestamp; - totalDistributedRewards: number; + rewards: AoEpochDistributionRewards; totalEligibleRewards: number; + totalEligibleObserverReward: number; + totalEligibleGatewayReward: number; + // TODO: we could create a new type for this + distributedTimestamp?: Timestamp; // only set if rewards have been distributed + totalDistributedRewards?: number; // only set if rewards have been distributed }; export type AoArNSReservedNameData = { From 491ea06f2f83ddde43d5fd708653035dd6d49fd7 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 27 Aug 2024 19:31:25 +0000 Subject: [PATCH 18/23] chore(release): 2.2.0-alpha.2 [skip ci] # [2.2.0-alpha.2](https://github.com/ar-io/ar-io-sdk/compare/v2.2.0-alpha.1...v2.2.0-alpha.2) (2024-08-27) ### Bug Fixes * **types:** update types for epoch distributions ([5aedf50](https://github.com/ar-io/ar-io-sdk/commit/5aedf5077a68faec8d86281a401ab2f4d6daf142)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- src/version.ts | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73b4b41b..e019d240 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [2.2.0-alpha.2](https://github.com/ar-io/ar-io-sdk/compare/v2.2.0-alpha.1...v2.2.0-alpha.2) (2024-08-27) + + +### Bug Fixes + +* **types:** update types for epoch distributions ([5aedf50](https://github.com/ar-io/ar-io-sdk/commit/5aedf5077a68faec8d86281a401ab2f4d6daf142)) + # [2.2.0-alpha.1](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0...v2.2.0-alpha.1) (2024-08-22) diff --git a/package.json b/package.json index 3a07e74b..16df9360 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ar.io/sdk", - "version": "2.2.0-alpha.1", + "version": "2.2.0-alpha.2", "repository": { "type": "git", "url": "git+https://github.com/ar-io/ar-io-sdk.git" diff --git a/src/version.ts b/src/version.ts index 1bfa62ac..4ce01dcb 100644 --- a/src/version.ts +++ b/src/version.ts @@ -17,4 +17,4 @@ // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH -export const version = '2.2.0-alpha.1'; +export const version = '2.2.0-alpha.2'; From 45df6267df3260744201aa86ced572e5da842aae Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Tue, 27 Aug 2024 10:39:19 -0600 Subject: [PATCH 19/23] fix(logger): permit logger as argument for typeguard util and default it --- src/utils/ao.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/ao.ts b/src/utils/ao.ts index 44dc268a..3e0af953 100644 --- a/src/utils/ao.ts +++ b/src/utils/ao.ts @@ -245,14 +245,16 @@ export const AntStateSchema = z * @returns {boolean} * @throws {z.ZodError} if the state object does not match the expected schema */ -export function isAoANTState(state: object): state is AoANTState { +export function isAoANTState( + state: object, + logger: Logger = Logger.default, +): state is AoANTState { try { AntStateSchema.parse(state); - return true; } catch (error) { // this allows us to see the path of the error in the object as well as the expected schema on invalid fields - Logger.default.error(error.issues); + logger.error(error.issues); return false; } } From e319e641d5a4162bfd63014327111914a96ca78a Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 28 Aug 2024 15:46:03 +0000 Subject: [PATCH 20/23] chore(release): 2.2.0-alpha.3 [skip ci] # [2.2.0-alpha.3](https://github.com/ar-io/ar-io-sdk/compare/v2.2.0-alpha.2...v2.2.0-alpha.3) (2024-08-28) ### Bug Fixes * **logger:** permit logger as argument for typeguard util and default it ([45df626](https://github.com/ar-io/ar-io-sdk/commit/45df6267df3260744201aa86ced572e5da842aae)) * **typeguard:** return true or false in typeguard and log the error ([4b851c5](https://github.com/ar-io/ar-io-sdk/commit/4b851c5bd904f66bd88efc67cdc239a1300c7ecf)) ### Features * **util:** add AoAntState typeguard util ([c6f457f](https://github.com/ar-io/ar-io-sdk/commit/c6f457f88f7b17af615ffacc593cc01b77230257)) --- CHANGELOG.md | 13 +++++++++++++ package.json | 2 +- src/version.ts | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e019d240..57bed9a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +# [2.2.0-alpha.3](https://github.com/ar-io/ar-io-sdk/compare/v2.2.0-alpha.2...v2.2.0-alpha.3) (2024-08-28) + + +### Bug Fixes + +* **logger:** permit logger as argument for typeguard util and default it ([45df626](https://github.com/ar-io/ar-io-sdk/commit/45df6267df3260744201aa86ced572e5da842aae)) +* **typeguard:** return true or false in typeguard and log the error ([4b851c5](https://github.com/ar-io/ar-io-sdk/commit/4b851c5bd904f66bd88efc67cdc239a1300c7ecf)) + + +### Features + +* **util:** add AoAntState typeguard util ([c6f457f](https://github.com/ar-io/ar-io-sdk/commit/c6f457f88f7b17af615ffacc593cc01b77230257)) + # [2.2.0-alpha.2](https://github.com/ar-io/ar-io-sdk/compare/v2.2.0-alpha.1...v2.2.0-alpha.2) (2024-08-27) diff --git a/package.json b/package.json index 16df9360..7ea7072f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ar.io/sdk", - "version": "2.2.0-alpha.2", + "version": "2.2.0-alpha.3", "repository": { "type": "git", "url": "git+https://github.com/ar-io/ar-io-sdk.git" diff --git a/src/version.ts b/src/version.ts index 4ce01dcb..c2a4c339 100644 --- a/src/version.ts +++ b/src/version.ts @@ -17,4 +17,4 @@ // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH -export const version = '2.2.0-alpha.2'; +export const version = '2.2.0-alpha.3'; From 350112d7fb29c180231b69ede5c4c2f94a60afa3 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Wed, 28 Aug 2024 09:50:46 -0600 Subject: [PATCH 21/23] fix(util): use ANTRegistry class for registering ant on spawn instead of aoconnect --- src/common/ant-registry.ts | 2 +- src/utils/ao.ts | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/common/ant-registry.ts b/src/common/ant-registry.ts index ae2c2a95..69e6c2a1 100644 --- a/src/common/ant-registry.ts +++ b/src/common/ant-registry.ts @@ -37,7 +37,7 @@ export class ANTRegistry { static init({ signer, ...config - }: WithSigner>): AoANTRegistryRead; + }: WithSigner>): AoANTRegistryWrite; static init( config?: OptionalSigner, ): AoANTRegistryRead | AoANTRegistryWrite { diff --git a/src/utils/ao.ts b/src/utils/ao.ts index 3e0af953..93befa5d 100644 --- a/src/utils/ao.ts +++ b/src/utils/ao.ts @@ -19,7 +19,7 @@ import { createData } from 'arbundles'; import { z } from 'zod'; import { defaultArweave } from '../common/arweave.js'; -import { AOProcess, Logger } from '../common/index.js'; +import { ANTRegistry, AOProcess, Logger } from '../common/index.js'; import { ANT_LUA_ID, ANT_REGISTRY_ID, @@ -61,12 +61,13 @@ export async function spawnANT({ stateContractTxId?: string; antRegistryId?: string; }): Promise { - // AoSigner is not a Contract Signer - should probably add that to the contract signer type - const registryClient = new AOProcess({ - processId: antRegistryId, - ao, + const registryClient = ANTRegistry.init({ + process: new AOProcess({ + processId: antRegistryId, + ao, + }), + signer: signer, }); - //TODO: cache locally and only fetch if not cached const luaString = (await defaultArweave.transactions.getData(luaCodeTxId, { decode: true, @@ -113,13 +114,7 @@ export async function spawnANT({ }); } - await registryClient.send({ - tags: [ - { name: 'Action', value: 'Register' }, - { name: 'Process-Id', value: processId }, - ], - signer, - }); + await registryClient.register({ processId }); return processId; } From e086ca96e39a536d16305041e1963a17a5deb007 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 28 Aug 2024 20:00:15 +0000 Subject: [PATCH 22/23] chore(release): 2.2.0-alpha.4 [skip ci] # [2.2.0-alpha.4](https://github.com/ar-io/ar-io-sdk/compare/v2.2.0-alpha.3...v2.2.0-alpha.4) (2024-08-28) ### Bug Fixes * **util:** use ANTRegistry class for registering ant on spawn instead of aoconnect ([350112d](https://github.com/ar-io/ar-io-sdk/commit/350112d7fb29c180231b69ede5c4c2f94a60afa3)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- src/version.ts | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57bed9a0..a9e9dc49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [2.2.0-alpha.4](https://github.com/ar-io/ar-io-sdk/compare/v2.2.0-alpha.3...v2.2.0-alpha.4) (2024-08-28) + + +### Bug Fixes + +* **util:** use ANTRegistry class for registering ant on spawn instead of aoconnect ([350112d](https://github.com/ar-io/ar-io-sdk/commit/350112d7fb29c180231b69ede5c4c2f94a60afa3)) + # [2.2.0-alpha.3](https://github.com/ar-io/ar-io-sdk/compare/v2.2.0-alpha.2...v2.2.0-alpha.3) (2024-08-28) diff --git a/package.json b/package.json index 7ea7072f..5c04ca67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ar.io/sdk", - "version": "2.2.0-alpha.3", + "version": "2.2.0-alpha.4", "repository": { "type": "git", "url": "git+https://github.com/ar-io/ar-io-sdk.git" diff --git a/src/version.ts b/src/version.ts index c2a4c339..5c6b180e 100644 --- a/src/version.ts +++ b/src/version.ts @@ -17,4 +17,4 @@ // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH -export const version = '2.2.0-alpha.3'; +export const version = '2.2.0-alpha.4'; From 6d72c57f21817eb8c2492f4bef3676ab15b38add Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Fri, 30 Aug 2024 11:58:59 -0600 Subject: [PATCH 23/23] chore(docs): prep changelog for release --- CHANGELOG.md | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9e9dc49..ec2d98f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,47 +1,3 @@ -# [2.2.0-alpha.4](https://github.com/ar-io/ar-io-sdk/compare/v2.2.0-alpha.3...v2.2.0-alpha.4) (2024-08-28) - - -### Bug Fixes - -* **util:** use ANTRegistry class for registering ant on spawn instead of aoconnect ([350112d](https://github.com/ar-io/ar-io-sdk/commit/350112d7fb29c180231b69ede5c4c2f94a60afa3)) - -# [2.2.0-alpha.3](https://github.com/ar-io/ar-io-sdk/compare/v2.2.0-alpha.2...v2.2.0-alpha.3) (2024-08-28) - - -### Bug Fixes - -* **logger:** permit logger as argument for typeguard util and default it ([45df626](https://github.com/ar-io/ar-io-sdk/commit/45df6267df3260744201aa86ced572e5da842aae)) -* **typeguard:** return true or false in typeguard and log the error ([4b851c5](https://github.com/ar-io/ar-io-sdk/commit/4b851c5bd904f66bd88efc67cdc239a1300c7ecf)) - - -### Features - -* **util:** add AoAntState typeguard util ([c6f457f](https://github.com/ar-io/ar-io-sdk/commit/c6f457f88f7b17af615ffacc593cc01b77230257)) - -# [2.2.0-alpha.2](https://github.com/ar-io/ar-io-sdk/compare/v2.2.0-alpha.1...v2.2.0-alpha.2) (2024-08-27) - - -### Bug Fixes - -* **types:** update types for epoch distributions ([5aedf50](https://github.com/ar-io/ar-io-sdk/commit/5aedf5077a68faec8d86281a401ab2f4d6daf142)) - -# [2.2.0-alpha.1](https://github.com/ar-io/ar-io-sdk/compare/v2.1.0...v2.2.0-alpha.1) (2024-08-22) - - -### Bug Fixes - -* **register:** update spawn ant to register at end of spawn ([4320c80](https://github.com/ar-io/ar-io-sdk/commit/4320c803bec96eedf4fe4bd5456a5eaa4ac9ae88)) -* **signer:** add typeguard util for aoSigner ([0d7f210](https://github.com/ar-io/ar-io-sdk/commit/0d7f210ac3ab44a1c7ea296936917e5297878e48)) -* **signing:** add aosigner to contract signer ([3b0495a](https://github.com/ar-io/ar-io-sdk/commit/3b0495a3ca4420c61cf4f72c7eb451777cbaf16d)) -* **tests:** dont send messages to ao in e2e tests ([e7108da](https://github.com/ar-io/ar-io-sdk/commit/e7108dafb7602e29833b0120c91cff73b022d31f)) -* **tests:** reconfigure test structure ([1872a26](https://github.com/ar-io/ar-io-sdk/commit/1872a262b654d72c779c2607ed454c5ae8271e87)) -* **tests:** use test-wallet fixture in tests instead of generating anew each time ([27a5dc2](https://github.com/ar-io/ar-io-sdk/commit/27a5dc25cd6bbe75736187280d3f511235dfa0b0)) - - -### Features - -* **ant id:** update lua ant id to latest ([968c30e](https://github.com/ar-io/ar-io-sdk/commit/968c30e9b3851c0eed1bb7e152e78835d558243b)) - # [2.1.0](https://github.com/ar-io/ar-io-sdk/compare/v2.0.2...v2.1.0) (2024-08-07)