From bf73e25b27ba948516fb442f0bfa39145454e3ea Mon Sep 17 00:00:00 2001 From: lbqds Date: Wed, 28 Feb 2024 15:06:45 +0800 Subject: [PATCH 1/9] Improve the return type of deployToDevnet --- packages/cli/src/codegen.ts | 16 ++++++---------- packages/cli/src/deployment.ts | 15 +++++++++++++-- packages/cli/src/utils.ts | 4 ++++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/packages/cli/src/codegen.ts b/packages/cli/src/codegen.ts index fbd57a05f..bffa5458f 100644 --- a/packages/cli/src/codegen.ts +++ b/packages/cli/src/codegen.ts @@ -34,7 +34,7 @@ import * as prettier from 'prettier' import path from 'path' import fs from 'fs' import { Configuration, DEFAULT_CONFIGURATION_VALUES } from './types' -import { getDeploymentFilePath } from './utils' +import { getDeploymentFilePath, taskIdToVariable } from './utils' import { Deployments, DeploymentsPerAddress } from './deployment' const header = `/* Autogenerated file. Do not edit manually. */\n/* tslint:disable */\n/* eslint-disable */\n\n` @@ -543,7 +543,7 @@ function genToDeployments(contracts: string[], optionalContracts: string[], allS const contractInstances = contracts.map((taskId) => { const typeName = getTypeFromTaskId(taskId) return ` - ${convertToVariableName(taskId)}: { + ${taskIdToVariable(taskId)}: { ...json.contracts['${taskId}'], contractInstance: ${typeName}.at(json.contracts['${taskId}'].contractInstance.address) } @@ -552,13 +552,13 @@ function genToDeployments(contracts: string[], optionalContracts: string[], allS const optionalContractInstances = optionalContracts.map((taskId) => { const typeName = getTypeFromTaskId(taskId) return ` - ${convertToVariableName(taskId)}: json.contracts['${taskId}'] === undefined ? undefined : { + ${taskIdToVariable(taskId)}: json.contracts['${taskId}'] === undefined ? undefined : { ...json.contracts['${taskId}'], contractInstance: ${typeName}.at(json.contracts['${taskId}'].contractInstance.address) } ` }) - const scripts = allScripts.map((taskId) => `${convertToVariableName(taskId)}: json.scripts['${taskId}']`).join(',') + const scripts = allScripts.map((taskId) => `${taskIdToVariable(taskId)}: json.scripts['${taskId}']`).join(',') const allContractInstances = contractInstances.concat(optionalContractInstances).join(',') return ` function toDeployments(json: any): Deployments { @@ -572,18 +572,14 @@ function genToDeployments(contracts: string[], optionalContracts: string[], allS ` } -function convertToVariableName(taskId: string): string { - return taskId.replace(/[:\-]/g, '_') -} - function genContractField(taskId: string, optional: boolean): string { const typeName = getTypeFromTaskId(taskId) - const varName = convertToVariableName(taskId) + const varName = taskIdToVariable(taskId) return `${varName}${optional ? '?' : ''}: DeployContractExecutionResult<${typeName}Instance>` } function genScriptField(taskId: string, optional: boolean): string { - const varName = convertToVariableName(taskId) + const varName = taskIdToVariable(taskId) return `${varName}${optional ? '?' : ''}: RunScriptResult` } diff --git a/packages/cli/src/deployment.ts b/packages/cli/src/deployment.ts index e2b56f32f..2496c1398 100644 --- a/packages/cli/src/deployment.ts +++ b/packages/cli/src/deployment.ts @@ -59,6 +59,7 @@ import { getNetwork, loadConfig, retryFetch, + taskIdToVariable, waitTxConfirmed, waitUserConfirmation } from './utils' @@ -644,11 +645,21 @@ async function deployInParallel( } } -export async function deployToDevnet(): Promise { +export async function deployToDevnet() { const deployments = Deployments.empty() const configuration = loadConfig(getConfigFile()) await deploy(configuration, 'devnet', deployments) - return deployments + return deployments.deployments.map((d) => { + const contracts: Record = {} + Array.from(d.contracts.entries()).forEach(([taskId, result]) => { + contracts[taskIdToVariable(taskId)] = result + }) + const scripts: Record = {} + Array.from(d.scripts.entries()).forEach(([taskId, result]) => { + scripts[taskIdToVariable(taskId)] = result + }) + return { deployerAddress: d.deployerAddress, contracts, scripts } + }) } async function deployToGroup( diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index 33d75a388..5fe78c141 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -152,3 +152,7 @@ export function waitUserConfirmation(msg: string): Promise { }) }) } + +export function taskIdToVariable(taskId: string): string { + return taskId.replace(/[:\-]/g, '_') +} From 9ca0b0d02bfcb8fa5b6f0f4168ad0ef786a35180 Mon Sep 17 00:00:00 2001 From: lbqds Date: Wed, 28 Feb 2024 20:37:14 +0800 Subject: [PATCH 2/9] Fix template tests --- packages/cli/templates/base/test/token.test.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/cli/templates/base/test/token.test.ts b/packages/cli/templates/base/test/token.test.ts index a7307d580..440052c54 100644 --- a/packages/cli/templates/base/test/token.test.ts +++ b/packages/cli/templates/base/test/token.test.ts @@ -1,7 +1,7 @@ -import { web3, Project, TestContractParams, addressFromContractId, AssetOutput, DUST_AMOUNT } from '@alephium/web3' +import { web3, Project, TestContractParams, addressFromContractId, AssetOutput, DUST_AMOUNT, groupOfAddress } from '@alephium/web3' import { expectAssertionError, randomContractId, testAddress, testNodeWallet } from '@alephium/web3-test' import { deployToDevnet } from '@alephium/cli' -import { TokenFaucet, TokenFaucetTypes, Withdraw } from '../artifacts/ts' +import { TokenFaucet, TokenFaucetInstance, TokenFaucetTypes, Withdraw } from '../artifacts/ts' describe('unit tests', () => { let testContractId: string @@ -109,7 +109,7 @@ describe('integration tests', () => { it('should withdraw on devnet', async () => { const signer = await testNodeWallet() - const deployments = await deployToDevnet() + const allDeployments = await deployToDevnet() // Test with all of the addresses of the wallet for (const account of await signer.getAccounts()) { @@ -117,23 +117,22 @@ describe('integration tests', () => { await signer.setSelectedAccount(testAddress) const testGroup = account.group - const deployed = deployments.getDeployedContractResult(testGroup, 'TokenFaucet') - if (deployed === undefined) { + const deployments = allDeployments.find((d) => groupOfAddress(d.deployerAddress) === testGroup) + if (deployments === undefined) { console.log(`The contract is not deployed on group ${account.group}`) continue } - const tokenId = deployed.contractInstance.contractId - const tokenAddress = deployed.contractInstance.address + const deployed = deployments.contracts.TokenFaucet expect(deployed.contractInstance.groupIndex).toEqual(testGroup) - const faucet = TokenFaucet.at(tokenAddress) + const faucet = deployed.contractInstance as TokenFaucetInstance const initialState = await faucet.fetchState() const initialBalance = initialState.fields.balance // Call `withdraw` function 10 times for (let i = 0; i < 10; i++) { await Withdraw.execute(signer, { - initialFields: { token: tokenId, amount: 1n }, + initialFields: { token: faucet.contractId, amount: 1n }, attoAlphAmount: DUST_AMOUNT * 2n }) From bef20b385ff3bdedf4b4bbd7b2d422492b8c6060 Mon Sep 17 00:00:00 2001 From: lbqds Date: Thu, 29 Feb 2024 10:28:28 +0800 Subject: [PATCH 3/9] Gen code to load contract instance from deployments --- packages/cli/src/codegen.ts | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/packages/cli/src/codegen.ts b/packages/cli/src/codegen.ts index bffa5458f..77d1c7089 100644 --- a/packages/cli/src/codegen.ts +++ b/packages/cli/src/codegen.ts @@ -379,8 +379,10 @@ function genContract(contract: Contract, artifactRelativePath: string): string { testMethod, callMethod, multicallMethods, fetchContractState, ContractInstance, getContractEventsCurrentCount } from '@alephium/web3' + import { DeployContractExecutionResult } from '@alephium/cli' import { default as ${contract.name}ContractJson } from '../${toUnixPath(artifactRelativePath)}' import { getContractByCodeHash } from './contracts' + import { loadContractInstanceFromDeployments } from './utils' // Custom types for the contract export namespace ${contract.name}Types { @@ -410,6 +412,22 @@ function genContract(contract: Contract, artifactRelativePath: string): string { super(address) } + static in( + allDeployments: { + deployerAddress: string, + contracts: Record + }[], + group?: number, + taskId?: string + ): ${contract.name}Instance | undefined { + return loadContractInstanceFromDeployments<${contract.name}Instance>( + allDeployments, + '${contract.name}', + group, + taskId + ) + } + ${genFetchState(contract)} ${genGetContractEventsCurrentCount(contract)} ${contract.eventsSig.map((e) => genSubscribeEvent(contract.name, e)).join('\n')} @@ -682,6 +700,39 @@ export function sortByName(artifacts: return artifacts.sort((a, b) => (a.artifact.name > b.artifact.name ? 1 : -1)) } +function genUtils(outDir: string) { + const utilsPath = path.join(outDir, 'utils.ts') + const source = ` + import { ContractInstance, groupOfAddress } from '@alephium/web3' + import { DeployContractExecutionResult } from '@alephium/cli' + + export function loadContractInstanceFromDeployments( + allDeployments: { + deployerAddress: string + contracts: Record + }[], + contractName: string, + group?: number, + taskId?: string + ): T | undefined { + const deployments = group === undefined + ? allDeployments[0] + : allDeployments.find((d) => groupOfAddress(d.deployerAddress)) + if (deployments === undefined) { + return undefined + } + const result = taskId === undefined + ? deployments.contracts[contractName] + : deployments.contracts[taskId.replace(/[:\-]/g, '_')] + if (result === undefined) { + return undefined + } + return result.contractInstance as T + } + ` + formatAndSaveToFile(utilsPath, header + source) +} + export function codegen(artifactDir: string) { const outDirTemp = path.join(artifactDir, 'ts') const outDir = path.isAbsolute(outDirTemp) ? outDirTemp : path.resolve(outDirTemp) @@ -692,6 +743,7 @@ export function codegen(artifactDir: string) { const exports: string[] = [] try { + genUtils(outDir) genContracts(outDir, artifactDir, exports) const contractNames = exports.map((p) => p.slice(2)) genContractByCodeHash(outDir, contractNames) From 08b1a3fcdc44f4d531f838eefaa3ae87e384ae64 Mon Sep 17 00:00:00 2001 From: lbqds Date: Thu, 29 Feb 2024 10:52:43 +0800 Subject: [PATCH 4/9] Do not remove the deployments.ts --- packages/cli/src/codegen.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/codegen.ts b/packages/cli/src/codegen.ts index 77d1c7089..891a737a9 100644 --- a/packages/cli/src/codegen.ts +++ b/packages/cli/src/codegen.ts @@ -733,11 +733,22 @@ function genUtils(outDir: string) { formatAndSaveToFile(utilsPath, header + source) } +function cleanCode(outDir: string) { + const files = fs.readdirSync(outDir) + files.forEach((file) => { + const filePath = path.join(outDir, file) + const filename = path.basename(file) + if (filename !== 'deployments.ts') { + fs.unlinkSync(filePath) + } + }) +} + export function codegen(artifactDir: string) { const outDirTemp = path.join(artifactDir, 'ts') const outDir = path.isAbsolute(outDirTemp) ? outDirTemp : path.resolve(outDirTemp) if (fs.existsSync(outDir)) { - fs.rmSync(outDir, { recursive: true, force: true }) + cleanCode(outDir) } fs.mkdirSync(outDir, { recursive: true }) From c3d803af46c59378616e38d43bc12d00fd9d6601 Mon Sep 17 00:00:00 2001 From: lbqds Date: Thu, 29 Feb 2024 11:05:56 +0800 Subject: [PATCH 5/9] Fix template tests --- packages/cli/templates/base/test/token.test.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/cli/templates/base/test/token.test.ts b/packages/cli/templates/base/test/token.test.ts index 440052c54..0f11a647f 100644 --- a/packages/cli/templates/base/test/token.test.ts +++ b/packages/cli/templates/base/test/token.test.ts @@ -117,15 +117,13 @@ describe('integration tests', () => { await signer.setSelectedAccount(testAddress) const testGroup = account.group - const deployments = allDeployments.find((d) => groupOfAddress(d.deployerAddress) === testGroup) - if (deployments === undefined) { + const faucet = TokenFaucetInstance.in(allDeployments, testGroup) + if (faucet === undefined) { console.log(`The contract is not deployed on group ${account.group}`) continue } - const deployed = deployments.contracts.TokenFaucet - expect(deployed.contractInstance.groupIndex).toEqual(testGroup) - const faucet = deployed.contractInstance as TokenFaucetInstance + expect(faucet.groupIndex).toEqual(testGroup) const initialState = await faucet.fetchState() const initialBalance = initialState.fields.balance From 3670483649fc5232e3d501774aad4726a7103ac4 Mon Sep 17 00:00:00 2001 From: lbqds Date: Thu, 29 Feb 2024 11:24:45 +0800 Subject: [PATCH 6/9] Update artifacts --- artifacts/ts/Add.ts | 18 +++++++++++ artifacts/ts/Assert.ts | 18 +++++++++++ artifacts/ts/Debug.ts | 18 +++++++++++ artifacts/ts/DeprecatedNFTTest1.ts | 18 +++++++++++ artifacts/ts/DeprecatedNFTTest2.ts | 18 +++++++++++ artifacts/ts/DeprecatedNFTTest3.ts | 18 +++++++++++ artifacts/ts/DeprecatedNFTTest4.ts | 18 +++++++++++ artifacts/ts/DeprecatedNFTTest5.ts | 18 +++++++++++ artifacts/ts/DeprecatedNFTTest6.ts | 18 +++++++++++ artifacts/ts/DeprecatedNFTTest7.ts | 18 +++++++++++ artifacts/ts/FakeTokenTest.ts | 18 +++++++++++ artifacts/ts/Greeter.ts | 18 +++++++++++ artifacts/ts/MetaData.ts | 18 +++++++++++ artifacts/ts/NFTCollectionTest.ts | 18 +++++++++++ artifacts/ts/NFTCollectionWithRoyaltyTest.ts | 18 +++++++++++ artifacts/ts/NFTTest.ts | 18 +++++++++++ artifacts/ts/OwnerOnly.ts | 18 +++++++++++ artifacts/ts/Sub.ts | 18 +++++++++++ artifacts/ts/TokenTest.ts | 18 +++++++++++ artifacts/ts/Warnings.ts | 18 +++++++++++ artifacts/ts/WrongNFTTest.ts | 18 +++++++++++ artifacts/ts/utils.ts | 32 ++++++++++++++++++++ 22 files changed, 410 insertions(+) create mode 100644 artifacts/ts/utils.ts diff --git a/artifacts/ts/Add.ts b/artifacts/ts/Add.ts index 5ef4f87c9..458fd69aa 100644 --- a/artifacts/ts/Add.ts +++ b/artifacts/ts/Add.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as AddContractJson } from "../add/Add.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace AddTypes { @@ -112,6 +114,22 @@ export class AddInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): AddInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "Add", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(Add, this); } diff --git a/artifacts/ts/Assert.ts b/artifacts/ts/Assert.ts index 22f27f533..9b380c24c 100644 --- a/artifacts/ts/Assert.ts +++ b/artifacts/ts/Assert.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as AssertContractJson } from "../test/Assert.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace AssertTypes { @@ -77,6 +79,22 @@ export class AssertInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): AssertInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "Assert", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(Assert, this); } diff --git a/artifacts/ts/Debug.ts b/artifacts/ts/Debug.ts index 97c20e392..b6676b14f 100644 --- a/artifacts/ts/Debug.ts +++ b/artifacts/ts/Debug.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DebugContractJson } from "../test/Debug.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DebugTypes { @@ -64,6 +66,22 @@ export class DebugInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): DebugInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "Debug", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(Debug, this); } diff --git a/artifacts/ts/DeprecatedNFTTest1.ts b/artifacts/ts/DeprecatedNFTTest1.ts index 58b727abe..a1eb6e8ba 100644 --- a/artifacts/ts/DeprecatedNFTTest1.ts +++ b/artifacts/ts/DeprecatedNFTTest1.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest1ContractJson } from "../nft/DeprecatedNFTTest1.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest1Types { @@ -95,6 +97,22 @@ export class DeprecatedNFTTest1Instance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): DeprecatedNFTTest1Instance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "DeprecatedNFTTest1", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest1, this); } diff --git a/artifacts/ts/DeprecatedNFTTest2.ts b/artifacts/ts/DeprecatedNFTTest2.ts index ab5980f35..0ec9c5e85 100644 --- a/artifacts/ts/DeprecatedNFTTest2.ts +++ b/artifacts/ts/DeprecatedNFTTest2.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest2ContractJson } from "../nft/DeprecatedNFTTest2.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest2Types { @@ -107,6 +109,22 @@ export class DeprecatedNFTTest2Instance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): DeprecatedNFTTest2Instance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "DeprecatedNFTTest2", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest2, this); } diff --git a/artifacts/ts/DeprecatedNFTTest3.ts b/artifacts/ts/DeprecatedNFTTest3.ts index cda537dc7..94903ab60 100644 --- a/artifacts/ts/DeprecatedNFTTest3.ts +++ b/artifacts/ts/DeprecatedNFTTest3.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest3ContractJson } from "../nft/DeprecatedNFTTest3.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest3Types { @@ -103,6 +105,22 @@ export class DeprecatedNFTTest3Instance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): DeprecatedNFTTest3Instance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "DeprecatedNFTTest3", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest3, this); } diff --git a/artifacts/ts/DeprecatedNFTTest4.ts b/artifacts/ts/DeprecatedNFTTest4.ts index 963659d87..134d78d4d 100644 --- a/artifacts/ts/DeprecatedNFTTest4.ts +++ b/artifacts/ts/DeprecatedNFTTest4.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest4ContractJson } from "../nft/DeprecatedNFTTest4.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest4Types { @@ -107,6 +109,22 @@ export class DeprecatedNFTTest4Instance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): DeprecatedNFTTest4Instance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "DeprecatedNFTTest4", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest4, this); } diff --git a/artifacts/ts/DeprecatedNFTTest5.ts b/artifacts/ts/DeprecatedNFTTest5.ts index c9fd895f3..ade267186 100644 --- a/artifacts/ts/DeprecatedNFTTest5.ts +++ b/artifacts/ts/DeprecatedNFTTest5.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest5ContractJson } from "../nft/DeprecatedNFTTest5.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest5Types { @@ -107,6 +109,22 @@ export class DeprecatedNFTTest5Instance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): DeprecatedNFTTest5Instance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "DeprecatedNFTTest5", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest5, this); } diff --git a/artifacts/ts/DeprecatedNFTTest6.ts b/artifacts/ts/DeprecatedNFTTest6.ts index 3d4b7824e..de001729e 100644 --- a/artifacts/ts/DeprecatedNFTTest6.ts +++ b/artifacts/ts/DeprecatedNFTTest6.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest6ContractJson } from "../nft/DeprecatedNFTTest6.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest6Types { @@ -107,6 +109,22 @@ export class DeprecatedNFTTest6Instance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): DeprecatedNFTTest6Instance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "DeprecatedNFTTest6", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest6, this); } diff --git a/artifacts/ts/DeprecatedNFTTest7.ts b/artifacts/ts/DeprecatedNFTTest7.ts index 084af2cfb..a8371fd7f 100644 --- a/artifacts/ts/DeprecatedNFTTest7.ts +++ b/artifacts/ts/DeprecatedNFTTest7.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest7ContractJson } from "../nft/DeprecatedNFTTest7.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest7Types { @@ -107,6 +109,22 @@ export class DeprecatedNFTTest7Instance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): DeprecatedNFTTest7Instance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "DeprecatedNFTTest7", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest7, this); } diff --git a/artifacts/ts/FakeTokenTest.ts b/artifacts/ts/FakeTokenTest.ts index dc39c2179..42b1bd727 100644 --- a/artifacts/ts/FakeTokenTest.ts +++ b/artifacts/ts/FakeTokenTest.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as FakeTokenTestContractJson } from "../token/FakeTokenTest.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace FakeTokenTestTypes { @@ -138,6 +140,22 @@ export class FakeTokenTestInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): FakeTokenTestInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "FakeTokenTest", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(FakeTokenTest, this); } diff --git a/artifacts/ts/Greeter.ts b/artifacts/ts/Greeter.ts index 73081746c..613299be6 100644 --- a/artifacts/ts/Greeter.ts +++ b/artifacts/ts/Greeter.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as GreeterContractJson } from "../greeter/Greeter.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace GreeterTypes { @@ -96,6 +98,22 @@ export class GreeterInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): GreeterInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "Greeter", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(Greeter, this); } diff --git a/artifacts/ts/MetaData.ts b/artifacts/ts/MetaData.ts index 3914a92ec..672887264 100644 --- a/artifacts/ts/MetaData.ts +++ b/artifacts/ts/MetaData.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as MetaDataContractJson } from "../test/MetaData.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace MetaDataTypes { @@ -80,6 +82,22 @@ export class MetaDataInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): MetaDataInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "MetaData", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(MetaData, this); } diff --git a/artifacts/ts/NFTCollectionTest.ts b/artifacts/ts/NFTCollectionTest.ts index c61702fc4..87f28b536 100644 --- a/artifacts/ts/NFTCollectionTest.ts +++ b/artifacts/ts/NFTCollectionTest.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as NFTCollectionTestContractJson } from "../nft/NFTCollectionTest.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace NFTCollectionTestTypes { @@ -148,6 +150,22 @@ export class NFTCollectionTestInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): NFTCollectionTestInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "NFTCollectionTest", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(NFTCollectionTest, this); } diff --git a/artifacts/ts/NFTCollectionWithRoyaltyTest.ts b/artifacts/ts/NFTCollectionWithRoyaltyTest.ts index 82b5970a4..fefd3c119 100644 --- a/artifacts/ts/NFTCollectionWithRoyaltyTest.ts +++ b/artifacts/ts/NFTCollectionWithRoyaltyTest.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as NFTCollectionWithRoyaltyTestContractJson } from "../nft/NFTCollectionWithRoyaltyTest.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace NFTCollectionWithRoyaltyTestTypes { @@ -179,6 +181,22 @@ export class NFTCollectionWithRoyaltyTestInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): NFTCollectionWithRoyaltyTestInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "NFTCollectionWithRoyaltyTest", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(NFTCollectionWithRoyaltyTest, this); } diff --git a/artifacts/ts/NFTTest.ts b/artifacts/ts/NFTTest.ts index 21ca75210..53c44f4ef 100644 --- a/artifacts/ts/NFTTest.ts +++ b/artifacts/ts/NFTTest.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as NFTTestContractJson } from "../nft/NFTTest.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace NFTTestTypes { @@ -99,6 +101,22 @@ export class NFTTestInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): NFTTestInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "NFTTest", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(NFTTest, this); } diff --git a/artifacts/ts/OwnerOnly.ts b/artifacts/ts/OwnerOnly.ts index 51434fa0e..64de7e9bc 100644 --- a/artifacts/ts/OwnerOnly.ts +++ b/artifacts/ts/OwnerOnly.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as OwnerOnlyContractJson } from "../test/OwnerOnly.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace OwnerOnlyTypes { @@ -72,6 +74,22 @@ export class OwnerOnlyInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): OwnerOnlyInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "OwnerOnly", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(OwnerOnly, this); } diff --git a/artifacts/ts/Sub.ts b/artifacts/ts/Sub.ts index ddd3c5816..ed387a0d1 100644 --- a/artifacts/ts/Sub.ts +++ b/artifacts/ts/Sub.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as SubContractJson } from "../sub/Sub.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace SubTypes { @@ -92,6 +94,22 @@ export class SubInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): SubInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "Sub", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(Sub, this); } diff --git a/artifacts/ts/TokenTest.ts b/artifacts/ts/TokenTest.ts index db9eb839d..5b4256986 100644 --- a/artifacts/ts/TokenTest.ts +++ b/artifacts/ts/TokenTest.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as TokenTestContractJson } from "../token/TokenTest.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace TokenTestTypes { @@ -121,6 +123,22 @@ export class TokenTestInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): TokenTestInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "TokenTest", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(TokenTest, this); } diff --git a/artifacts/ts/Warnings.ts b/artifacts/ts/Warnings.ts index 1b9ed67a4..b791f38cb 100644 --- a/artifacts/ts/Warnings.ts +++ b/artifacts/ts/Warnings.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as WarningsContractJson } from "../test/Warnings.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace WarningsTypes { @@ -72,6 +74,22 @@ export class WarningsInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): WarningsInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "Warnings", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(Warnings, this); } diff --git a/artifacts/ts/WrongNFTTest.ts b/artifacts/ts/WrongNFTTest.ts index 435ba942d..55feef817 100644 --- a/artifacts/ts/WrongNFTTest.ts +++ b/artifacts/ts/WrongNFTTest.ts @@ -24,8 +24,10 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; import { default as WrongNFTTestContractJson } from "../nft/WrongNFTTest.ral.json"; import { getContractByCodeHash } from "./contracts"; +import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace WrongNFTTestTypes { @@ -108,6 +110,22 @@ export class WrongNFTTestInstance extends ContractInstance { super(address); } + static in( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + group?: number, + taskId?: string + ): WrongNFTTestInstance | undefined { + return loadContractInstanceFromDeployments( + allDeployments, + "WrongNFTTest", + group, + taskId + ); + } + async fetchState(): Promise { return fetchContractState(WrongNFTTest, this); } diff --git a/artifacts/ts/utils.ts b/artifacts/ts/utils.ts new file mode 100644 index 000000000..faf9f4cd3 --- /dev/null +++ b/artifacts/ts/utils.ts @@ -0,0 +1,32 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { ContractInstance, groupOfAddress } from "@alephium/web3"; +import { DeployContractExecutionResult } from "@alephium/cli"; + +export function loadContractInstanceFromDeployments( + allDeployments: { + deployerAddress: string; + contracts: Record; + }[], + contractName: string, + group?: number, + taskId?: string +): T | undefined { + const deployments = + group === undefined + ? allDeployments[0] + : allDeployments.find((d) => groupOfAddress(d.deployerAddress)); + if (deployments === undefined) { + return undefined; + } + const result = + taskId === undefined + ? deployments.contracts[contractName] + : deployments.contracts[taskId.replace(/[:-]/g, "_")]; + if (result === undefined) { + return undefined; + } + return result.contractInstance as T; +} From a03978e3cb77caf07291bb57ce3bdb1e706a47e8 Mon Sep 17 00:00:00 2001 From: lbqds Date: Thu, 29 Feb 2024 18:17:35 +0800 Subject: [PATCH 7/9] Add getInstance to Deployments --- packages/cli/src/codegen.ts | 52 ------------------- packages/cli/src/deployment.test.ts | 35 ++++++++++++- packages/cli/src/deployment.ts | 40 +++++++++----- .../cli/templates/base/test/token.test.ts | 6 +-- 4 files changed, 65 insertions(+), 68 deletions(-) diff --git a/packages/cli/src/codegen.ts b/packages/cli/src/codegen.ts index 891a737a9..a61e6020f 100644 --- a/packages/cli/src/codegen.ts +++ b/packages/cli/src/codegen.ts @@ -379,10 +379,8 @@ function genContract(contract: Contract, artifactRelativePath: string): string { testMethod, callMethod, multicallMethods, fetchContractState, ContractInstance, getContractEventsCurrentCount } from '@alephium/web3' - import { DeployContractExecutionResult } from '@alephium/cli' import { default as ${contract.name}ContractJson } from '../${toUnixPath(artifactRelativePath)}' import { getContractByCodeHash } from './contracts' - import { loadContractInstanceFromDeployments } from './utils' // Custom types for the contract export namespace ${contract.name}Types { @@ -412,22 +410,6 @@ function genContract(contract: Contract, artifactRelativePath: string): string { super(address) } - static in( - allDeployments: { - deployerAddress: string, - contracts: Record - }[], - group?: number, - taskId?: string - ): ${contract.name}Instance | undefined { - return loadContractInstanceFromDeployments<${contract.name}Instance>( - allDeployments, - '${contract.name}', - group, - taskId - ) - } - ${genFetchState(contract)} ${genGetContractEventsCurrentCount(contract)} ${contract.eventsSig.map((e) => genSubscribeEvent(contract.name, e)).join('\n')} @@ -700,39 +682,6 @@ export function sortByName(artifacts: return artifacts.sort((a, b) => (a.artifact.name > b.artifact.name ? 1 : -1)) } -function genUtils(outDir: string) { - const utilsPath = path.join(outDir, 'utils.ts') - const source = ` - import { ContractInstance, groupOfAddress } from '@alephium/web3' - import { DeployContractExecutionResult } from '@alephium/cli' - - export function loadContractInstanceFromDeployments( - allDeployments: { - deployerAddress: string - contracts: Record - }[], - contractName: string, - group?: number, - taskId?: string - ): T | undefined { - const deployments = group === undefined - ? allDeployments[0] - : allDeployments.find((d) => groupOfAddress(d.deployerAddress)) - if (deployments === undefined) { - return undefined - } - const result = taskId === undefined - ? deployments.contracts[contractName] - : deployments.contracts[taskId.replace(/[:\-]/g, '_')] - if (result === undefined) { - return undefined - } - return result.contractInstance as T - } - ` - formatAndSaveToFile(utilsPath, header + source) -} - function cleanCode(outDir: string) { const files = fs.readdirSync(outDir) files.forEach((file) => { @@ -754,7 +703,6 @@ export function codegen(artifactDir: string) { const exports: string[] = [] try { - genUtils(outDir) genContracts(outDir, artifactDir, exports) const contractNames = exports.map((p) => p.slice(2)) genContractByCodeHash(outDir, contractNames) diff --git a/packages/cli/src/deployment.test.ts b/packages/cli/src/deployment.test.ts index 4febf4158..ec32cca79 100644 --- a/packages/cli/src/deployment.test.ts +++ b/packages/cli/src/deployment.test.ts @@ -18,7 +18,9 @@ along with the library. If not, see . import { PrivateKeyWallet } from '@alephium/web3-wallet' import { Deployments, DeploymentsPerAddress, recordEqual, validatePrivateKeys } from './deployment' -import { web3 } from '@alephium/web3' +import { ContractInstance, web3 } from '@alephium/web3' +import { randomContractAddress, testAddress } from '@alephium/web3-test' +import { DeployContractExecutionResult } from './types' describe('deployments', () => { it('test record equal', () => { @@ -85,4 +87,35 @@ describe('deployments', () => { expect(() => validatePrivateKeys(keys.join(','))).toThrowError(`Duplicated private keys on group ${size - 1}`) }) }) + + it('should get contract instance from deployments', () => { + class FakeContractInstance extends ContractInstance {} + function fake(): DeployContractExecutionResult { + return { + contractInstance: new FakeContractInstance(randomContractAddress()), + txId: '', + unsignedTx: '', + signature: '', + gasAmount: 0, + gasPrice: '', + blockHash: '', + codeHash: '' + } + } + + const contracts = new Map() + contracts.set('Foo', fake()) + contracts.set('Bar', fake()) + contracts.set('Baz_1', fake()) + const deployments = new Deployments([new DeploymentsPerAddress(testAddress, contracts, new Map(), new Map())]) + + expect(deployments['tryGetDeployedContract']('Foo')).toEqual(contracts.get('Foo')!) + expect(deployments['tryGetDeployedContract']('Bar')).toEqual(contracts.get('Bar')!) + expect(deployments['tryGetDeployedContract']('Foo', 1)).toEqual(undefined) + expect(deployments['tryGetDeployedContract']('Bar', 1)).toEqual(undefined) + expect(deployments['tryGetDeployedContract']('Baz')).toEqual(undefined) + expect(deployments['tryGetDeployedContract']('Foo', undefined, 'Foo:1')).toEqual(undefined) + expect(deployments['tryGetDeployedContract']('Baz', undefined, 'Baz:1')).toEqual(contracts.get('Baz_1')) + expect(deployments['tryGetDeployedContract']('Baz', undefined, 'Baz:2')).toEqual(undefined) + }) }) diff --git a/packages/cli/src/deployment.ts b/packages/cli/src/deployment.ts index 2496c1398..630251f0c 100644 --- a/packages/cli/src/deployment.ts +++ b/packages/cli/src/deployment.ts @@ -158,6 +158,32 @@ export class Deployments { const deploymentsFile = getDeploymentFilePath(configuration, networkId) return Deployments.from(deploymentsFile) } + + private tryGetDeployedContract( + contractName: string, + group?: number, + taskId?: string + ): DeployContractExecutionResult | undefined { + const deployments = group !== undefined ? this.deploymentsByGroup(group) : this.deployments[0] + if (deployments === undefined) { + return undefined + } + return taskId === undefined + ? deployments.contracts.get(`${contractName}`) + : deployments.contracts.get(`${taskIdToVariable(taskId)}`) + } + + getInstance( + contract: ContractFactory, + group?: number, + taskId?: string + ): I | undefined { + const result = this.tryGetDeployedContract(contract.contract.name, group, taskId) + if (result === undefined) { + return undefined + } + return contract.at(result.contractInstance.address) + } } export async function getDeploymentResult(filepath: string): Promise { @@ -645,21 +671,11 @@ async function deployInParallel( } } -export async function deployToDevnet() { +export async function deployToDevnet(): Promise { const deployments = Deployments.empty() const configuration = loadConfig(getConfigFile()) await deploy(configuration, 'devnet', deployments) - return deployments.deployments.map((d) => { - const contracts: Record = {} - Array.from(d.contracts.entries()).forEach(([taskId, result]) => { - contracts[taskIdToVariable(taskId)] = result - }) - const scripts: Record = {} - Array.from(d.scripts.entries()).forEach(([taskId, result]) => { - scripts[taskIdToVariable(taskId)] = result - }) - return { deployerAddress: d.deployerAddress, contracts, scripts } - }) + return deployments } async function deployToGroup( diff --git a/packages/cli/templates/base/test/token.test.ts b/packages/cli/templates/base/test/token.test.ts index 0f11a647f..ab804376a 100644 --- a/packages/cli/templates/base/test/token.test.ts +++ b/packages/cli/templates/base/test/token.test.ts @@ -1,7 +1,7 @@ import { web3, Project, TestContractParams, addressFromContractId, AssetOutput, DUST_AMOUNT, groupOfAddress } from '@alephium/web3' import { expectAssertionError, randomContractId, testAddress, testNodeWallet } from '@alephium/web3-test' import { deployToDevnet } from '@alephium/cli' -import { TokenFaucet, TokenFaucetInstance, TokenFaucetTypes, Withdraw } from '../artifacts/ts' +import { TokenFaucet, TokenFaucetTypes, Withdraw } from '../artifacts/ts' describe('unit tests', () => { let testContractId: string @@ -109,7 +109,7 @@ describe('integration tests', () => { it('should withdraw on devnet', async () => { const signer = await testNodeWallet() - const allDeployments = await deployToDevnet() + const deployments = await deployToDevnet() // Test with all of the addresses of the wallet for (const account of await signer.getAccounts()) { @@ -117,7 +117,7 @@ describe('integration tests', () => { await signer.setSelectedAccount(testAddress) const testGroup = account.group - const faucet = TokenFaucetInstance.in(allDeployments, testGroup) + const faucet = deployments.getInstance(TokenFaucet) if (faucet === undefined) { console.log(`The contract is not deployed on group ${account.group}`) continue From ba7aa0deb06762bf3a875a18fdc90161dd89bab5 Mon Sep 17 00:00:00 2001 From: lbqds Date: Thu, 29 Feb 2024 19:03:27 +0800 Subject: [PATCH 8/9] Update artifacts --- artifacts/ts/Add.ts | 18 ----------- artifacts/ts/Assert.ts | 18 ----------- artifacts/ts/Debug.ts | 18 ----------- artifacts/ts/DeprecatedNFTTest1.ts | 18 ----------- artifacts/ts/DeprecatedNFTTest2.ts | 18 ----------- artifacts/ts/DeprecatedNFTTest3.ts | 18 ----------- artifacts/ts/DeprecatedNFTTest4.ts | 18 ----------- artifacts/ts/DeprecatedNFTTest5.ts | 18 ----------- artifacts/ts/DeprecatedNFTTest6.ts | 18 ----------- artifacts/ts/DeprecatedNFTTest7.ts | 18 ----------- artifacts/ts/FakeTokenTest.ts | 18 ----------- artifacts/ts/Greeter.ts | 18 ----------- artifacts/ts/MetaData.ts | 18 ----------- artifacts/ts/NFTCollectionTest.ts | 18 ----------- artifacts/ts/NFTCollectionWithRoyaltyTest.ts | 18 ----------- artifacts/ts/NFTTest.ts | 18 ----------- artifacts/ts/OwnerOnly.ts | 18 ----------- artifacts/ts/Sub.ts | 18 ----------- artifacts/ts/TokenTest.ts | 18 ----------- artifacts/ts/Warnings.ts | 18 ----------- artifacts/ts/WrongNFTTest.ts | 18 ----------- artifacts/ts/utils.ts | 32 -------------------- 22 files changed, 410 deletions(-) delete mode 100644 artifacts/ts/utils.ts diff --git a/artifacts/ts/Add.ts b/artifacts/ts/Add.ts index 458fd69aa..5ef4f87c9 100644 --- a/artifacts/ts/Add.ts +++ b/artifacts/ts/Add.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as AddContractJson } from "../add/Add.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace AddTypes { @@ -114,22 +112,6 @@ export class AddInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): AddInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "Add", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(Add, this); } diff --git a/artifacts/ts/Assert.ts b/artifacts/ts/Assert.ts index 9b380c24c..22f27f533 100644 --- a/artifacts/ts/Assert.ts +++ b/artifacts/ts/Assert.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as AssertContractJson } from "../test/Assert.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace AssertTypes { @@ -79,22 +77,6 @@ export class AssertInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): AssertInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "Assert", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(Assert, this); } diff --git a/artifacts/ts/Debug.ts b/artifacts/ts/Debug.ts index b6676b14f..97c20e392 100644 --- a/artifacts/ts/Debug.ts +++ b/artifacts/ts/Debug.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DebugContractJson } from "../test/Debug.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DebugTypes { @@ -66,22 +64,6 @@ export class DebugInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): DebugInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "Debug", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(Debug, this); } diff --git a/artifacts/ts/DeprecatedNFTTest1.ts b/artifacts/ts/DeprecatedNFTTest1.ts index a1eb6e8ba..58b727abe 100644 --- a/artifacts/ts/DeprecatedNFTTest1.ts +++ b/artifacts/ts/DeprecatedNFTTest1.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest1ContractJson } from "../nft/DeprecatedNFTTest1.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest1Types { @@ -97,22 +95,6 @@ export class DeprecatedNFTTest1Instance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): DeprecatedNFTTest1Instance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "DeprecatedNFTTest1", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest1, this); } diff --git a/artifacts/ts/DeprecatedNFTTest2.ts b/artifacts/ts/DeprecatedNFTTest2.ts index 0ec9c5e85..ab5980f35 100644 --- a/artifacts/ts/DeprecatedNFTTest2.ts +++ b/artifacts/ts/DeprecatedNFTTest2.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest2ContractJson } from "../nft/DeprecatedNFTTest2.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest2Types { @@ -109,22 +107,6 @@ export class DeprecatedNFTTest2Instance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): DeprecatedNFTTest2Instance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "DeprecatedNFTTest2", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest2, this); } diff --git a/artifacts/ts/DeprecatedNFTTest3.ts b/artifacts/ts/DeprecatedNFTTest3.ts index 94903ab60..cda537dc7 100644 --- a/artifacts/ts/DeprecatedNFTTest3.ts +++ b/artifacts/ts/DeprecatedNFTTest3.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest3ContractJson } from "../nft/DeprecatedNFTTest3.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest3Types { @@ -105,22 +103,6 @@ export class DeprecatedNFTTest3Instance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): DeprecatedNFTTest3Instance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "DeprecatedNFTTest3", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest3, this); } diff --git a/artifacts/ts/DeprecatedNFTTest4.ts b/artifacts/ts/DeprecatedNFTTest4.ts index 134d78d4d..963659d87 100644 --- a/artifacts/ts/DeprecatedNFTTest4.ts +++ b/artifacts/ts/DeprecatedNFTTest4.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest4ContractJson } from "../nft/DeprecatedNFTTest4.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest4Types { @@ -109,22 +107,6 @@ export class DeprecatedNFTTest4Instance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): DeprecatedNFTTest4Instance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "DeprecatedNFTTest4", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest4, this); } diff --git a/artifacts/ts/DeprecatedNFTTest5.ts b/artifacts/ts/DeprecatedNFTTest5.ts index ade267186..c9fd895f3 100644 --- a/artifacts/ts/DeprecatedNFTTest5.ts +++ b/artifacts/ts/DeprecatedNFTTest5.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest5ContractJson } from "../nft/DeprecatedNFTTest5.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest5Types { @@ -109,22 +107,6 @@ export class DeprecatedNFTTest5Instance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): DeprecatedNFTTest5Instance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "DeprecatedNFTTest5", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest5, this); } diff --git a/artifacts/ts/DeprecatedNFTTest6.ts b/artifacts/ts/DeprecatedNFTTest6.ts index de001729e..3d4b7824e 100644 --- a/artifacts/ts/DeprecatedNFTTest6.ts +++ b/artifacts/ts/DeprecatedNFTTest6.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest6ContractJson } from "../nft/DeprecatedNFTTest6.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest6Types { @@ -109,22 +107,6 @@ export class DeprecatedNFTTest6Instance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): DeprecatedNFTTest6Instance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "DeprecatedNFTTest6", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest6, this); } diff --git a/artifacts/ts/DeprecatedNFTTest7.ts b/artifacts/ts/DeprecatedNFTTest7.ts index a8371fd7f..084af2cfb 100644 --- a/artifacts/ts/DeprecatedNFTTest7.ts +++ b/artifacts/ts/DeprecatedNFTTest7.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as DeprecatedNFTTest7ContractJson } from "../nft/DeprecatedNFTTest7.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace DeprecatedNFTTest7Types { @@ -109,22 +107,6 @@ export class DeprecatedNFTTest7Instance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): DeprecatedNFTTest7Instance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "DeprecatedNFTTest7", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(DeprecatedNFTTest7, this); } diff --git a/artifacts/ts/FakeTokenTest.ts b/artifacts/ts/FakeTokenTest.ts index 42b1bd727..dc39c2179 100644 --- a/artifacts/ts/FakeTokenTest.ts +++ b/artifacts/ts/FakeTokenTest.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as FakeTokenTestContractJson } from "../token/FakeTokenTest.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace FakeTokenTestTypes { @@ -140,22 +138,6 @@ export class FakeTokenTestInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): FakeTokenTestInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "FakeTokenTest", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(FakeTokenTest, this); } diff --git a/artifacts/ts/Greeter.ts b/artifacts/ts/Greeter.ts index 613299be6..73081746c 100644 --- a/artifacts/ts/Greeter.ts +++ b/artifacts/ts/Greeter.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as GreeterContractJson } from "../greeter/Greeter.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace GreeterTypes { @@ -98,22 +96,6 @@ export class GreeterInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): GreeterInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "Greeter", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(Greeter, this); } diff --git a/artifacts/ts/MetaData.ts b/artifacts/ts/MetaData.ts index 672887264..3914a92ec 100644 --- a/artifacts/ts/MetaData.ts +++ b/artifacts/ts/MetaData.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as MetaDataContractJson } from "../test/MetaData.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace MetaDataTypes { @@ -82,22 +80,6 @@ export class MetaDataInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): MetaDataInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "MetaData", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(MetaData, this); } diff --git a/artifacts/ts/NFTCollectionTest.ts b/artifacts/ts/NFTCollectionTest.ts index 87f28b536..c61702fc4 100644 --- a/artifacts/ts/NFTCollectionTest.ts +++ b/artifacts/ts/NFTCollectionTest.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as NFTCollectionTestContractJson } from "../nft/NFTCollectionTest.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace NFTCollectionTestTypes { @@ -150,22 +148,6 @@ export class NFTCollectionTestInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): NFTCollectionTestInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "NFTCollectionTest", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(NFTCollectionTest, this); } diff --git a/artifacts/ts/NFTCollectionWithRoyaltyTest.ts b/artifacts/ts/NFTCollectionWithRoyaltyTest.ts index fefd3c119..82b5970a4 100644 --- a/artifacts/ts/NFTCollectionWithRoyaltyTest.ts +++ b/artifacts/ts/NFTCollectionWithRoyaltyTest.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as NFTCollectionWithRoyaltyTestContractJson } from "../nft/NFTCollectionWithRoyaltyTest.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace NFTCollectionWithRoyaltyTestTypes { @@ -181,22 +179,6 @@ export class NFTCollectionWithRoyaltyTestInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): NFTCollectionWithRoyaltyTestInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "NFTCollectionWithRoyaltyTest", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(NFTCollectionWithRoyaltyTest, this); } diff --git a/artifacts/ts/NFTTest.ts b/artifacts/ts/NFTTest.ts index 53c44f4ef..21ca75210 100644 --- a/artifacts/ts/NFTTest.ts +++ b/artifacts/ts/NFTTest.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as NFTTestContractJson } from "../nft/NFTTest.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace NFTTestTypes { @@ -101,22 +99,6 @@ export class NFTTestInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): NFTTestInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "NFTTest", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(NFTTest, this); } diff --git a/artifacts/ts/OwnerOnly.ts b/artifacts/ts/OwnerOnly.ts index 64de7e9bc..51434fa0e 100644 --- a/artifacts/ts/OwnerOnly.ts +++ b/artifacts/ts/OwnerOnly.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as OwnerOnlyContractJson } from "../test/OwnerOnly.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace OwnerOnlyTypes { @@ -74,22 +72,6 @@ export class OwnerOnlyInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): OwnerOnlyInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "OwnerOnly", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(OwnerOnly, this); } diff --git a/artifacts/ts/Sub.ts b/artifacts/ts/Sub.ts index ed387a0d1..ddd3c5816 100644 --- a/artifacts/ts/Sub.ts +++ b/artifacts/ts/Sub.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as SubContractJson } from "../sub/Sub.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace SubTypes { @@ -94,22 +92,6 @@ export class SubInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): SubInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "Sub", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(Sub, this); } diff --git a/artifacts/ts/TokenTest.ts b/artifacts/ts/TokenTest.ts index 5b4256986..db9eb839d 100644 --- a/artifacts/ts/TokenTest.ts +++ b/artifacts/ts/TokenTest.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as TokenTestContractJson } from "../token/TokenTest.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace TokenTestTypes { @@ -123,22 +121,6 @@ export class TokenTestInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): TokenTestInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "TokenTest", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(TokenTest, this); } diff --git a/artifacts/ts/Warnings.ts b/artifacts/ts/Warnings.ts index b791f38cb..1b9ed67a4 100644 --- a/artifacts/ts/Warnings.ts +++ b/artifacts/ts/Warnings.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as WarningsContractJson } from "../test/Warnings.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace WarningsTypes { @@ -74,22 +72,6 @@ export class WarningsInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): WarningsInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "Warnings", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(Warnings, this); } diff --git a/artifacts/ts/WrongNFTTest.ts b/artifacts/ts/WrongNFTTest.ts index 55feef817..435ba942d 100644 --- a/artifacts/ts/WrongNFTTest.ts +++ b/artifacts/ts/WrongNFTTest.ts @@ -24,10 +24,8 @@ import { ContractInstance, getContractEventsCurrentCount, } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; import { default as WrongNFTTestContractJson } from "../nft/WrongNFTTest.ral.json"; import { getContractByCodeHash } from "./contracts"; -import { loadContractInstanceFromDeployments } from "./utils"; // Custom types for the contract export namespace WrongNFTTestTypes { @@ -110,22 +108,6 @@ export class WrongNFTTestInstance extends ContractInstance { super(address); } - static in( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - group?: number, - taskId?: string - ): WrongNFTTestInstance | undefined { - return loadContractInstanceFromDeployments( - allDeployments, - "WrongNFTTest", - group, - taskId - ); - } - async fetchState(): Promise { return fetchContractState(WrongNFTTest, this); } diff --git a/artifacts/ts/utils.ts b/artifacts/ts/utils.ts deleted file mode 100644 index faf9f4cd3..000000000 --- a/artifacts/ts/utils.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* Autogenerated file. Do not edit manually. */ -/* tslint:disable */ -/* eslint-disable */ - -import { ContractInstance, groupOfAddress } from "@alephium/web3"; -import { DeployContractExecutionResult } from "@alephium/cli"; - -export function loadContractInstanceFromDeployments( - allDeployments: { - deployerAddress: string; - contracts: Record; - }[], - contractName: string, - group?: number, - taskId?: string -): T | undefined { - const deployments = - group === undefined - ? allDeployments[0] - : allDeployments.find((d) => groupOfAddress(d.deployerAddress)); - if (deployments === undefined) { - return undefined; - } - const result = - taskId === undefined - ? deployments.contracts[contractName] - : deployments.contracts[taskId.replace(/[:-]/g, "_")]; - if (result === undefined) { - return undefined; - } - return result.contractInstance as T; -} From ed0090e0c6cd4c7734ade1ee89aad34a933527d2 Mon Sep 17 00:00:00 2001 From: lbqds Date: Thu, 29 Feb 2024 20:12:51 +0800 Subject: [PATCH 9/9] Fix deployment tests --- packages/cli/templates/base/test/token.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/templates/base/test/token.test.ts b/packages/cli/templates/base/test/token.test.ts index ab804376a..21c8aebfb 100644 --- a/packages/cli/templates/base/test/token.test.ts +++ b/packages/cli/templates/base/test/token.test.ts @@ -117,7 +117,7 @@ describe('integration tests', () => { await signer.setSelectedAccount(testAddress) const testGroup = account.group - const faucet = deployments.getInstance(TokenFaucet) + const faucet = deployments.getInstance(TokenFaucet, testGroup) if (faucet === undefined) { console.log(`The contract is not deployed on group ${account.group}`) continue