Skip to content

Commit

Permalink
feat: migrating to latest beta prereleases of utils, utils-debug and …
Browse files Browse the repository at this point in the history
…generator
  • Loading branch information
aorumbayev committed Oct 15, 2024
1 parent 42feefa commit 60700af
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import * as algokit from '@algorandfoundation/algokit-utils'
import { {{ contract_name.split('_')|map('capitalize')|join }}Client } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client'
import { {{ contract_name.split('_')|map('capitalize')|join }}Factory } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client'

// Below is a showcase of various deployment options you can use in TypeScript Client
export async function deploy() {
console.log('=== Deploying {{ contract_name.split('_')|map('capitalize')|join }} ===')

const algorand = algokit.AlgorandClient.fromEnvironment()
const deployer = await algorand.account.fromEnvironment('DEPLOYER')

const appClient = algorand.client.getTypedAppClientByCreatorAndName({{ contract_name.split('_')|map('capitalize')|join }}Client, {
sender: deployer,
creatorAddress: deployer.addr,
})

const app = await appClient.deploy({
onSchemaBreak: 'append',
onUpdate: 'append',
const factory = algorand.client.getTypedAppFactory({{ contract_name.split('_')|map('capitalize')|join }}Factory, {
defaultSender: deployer.addr,
})

const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' })

// If app was just created fund the app account
if (['create', 'replace'].includes(app.operationPerformed)) {
if (['create', 'replace'].includes(result.operationPerformed)) {
await algorand.send.payment({
amount: algokit.algos(1),
amount: (1).algo(),
sender: deployer.addr,
receiver: app.appAddress,
})
}

const method = 'hello'
const response = await appClient.hello({ name: 'world' })
console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`)
const method = 'hello'
const response = await appClient.send.hello({
args: { name: 'world' },
})
console.log(
`Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
"npm": ">=9.0"
},
"dependencies": {
"@algorandfoundation/algokit-utils": "^6.0.2",
"@algorandfoundation/algokit-utils": "7.0.0-beta.14",
"@algorandfoundation/algokit-utils-debug": "v1.0.2-beta.2",
"algosdk": "^2.7.0"
},
"devDependencies": {
"@algorandfoundation/algokit-client-generator": "^3.0.3",
"@algorandfoundation/algokit-client-generator": "v4.0.0-beta.5",
"@types/jest": "^29.5.11",
"dotenv": "^16.0.3",
"prettier": "^2.8.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import * as algokit from '@algorandfoundation/algokit-utils'
import { CoolContractClient } from '../artifacts/cool_contract/CoolContractClient'
import { CoolContractFactory } from '../artifacts/cool_contract/CoolContractClient'

// Below is a showcase of various deployment options you can use in TypeScript Client
export async function deploy() {
console.log('=== Deploying CoolContract ===')

const algorand = algokit.AlgorandClient.fromEnvironment()
const deployer = await algorand.account.fromEnvironment('DEPLOYER')

const appClient = algorand.client.getTypedAppClientByCreatorAndName(CoolContractClient, {
sender: deployer,
creatorAddress: deployer.addr,
})

const app = await appClient.deploy({
onSchemaBreak: 'append',
onUpdate: 'append',
const factory = algorand.client.getTypedAppFactory(CoolContractFactory, {
defaultSender: deployer.addr,
})

const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' })

// If app was just created fund the app account
if (['create', 'replace'].includes(app.operationPerformed)) {
if (['create', 'replace'].includes(result.operationPerformed)) {
await algorand.send.payment({
amount: algokit.algos(1),
amount: (1).algo(),
sender: deployer.addr,
receiver: app.appAddress,
})
}

const method = 'hello'
const response = await appClient.hello({ name: 'world' })
console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`)
const method = 'hello'
const response = await appClient.send.hello({
args: { name: 'world' },
})
console.log(
`Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`,
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as algokit from '@algorandfoundation/algokit-utils'
import { HelloWorldClient } from '../artifacts/hello_world/HelloWorldClient'
import { HelloWorldFactory } from '../artifacts/hello_world/HelloWorldClient'

// Below is a showcase of various deployment options you can use in TypeScript Client
export async function deploy() {
Expand All @@ -8,26 +8,26 @@ export async function deploy() {
const algorand = algokit.AlgorandClient.fromEnvironment()
const deployer = await algorand.account.fromEnvironment('DEPLOYER')

const appClient = algorand.client.getTypedAppClientByCreatorAndName(HelloWorldClient, {
sender: deployer,
creatorAddress: deployer.addr,
const factory = algorand.client.getTypedAppFactory(HelloWorldFactory, {
defaultSender: deployer.addr,
})

const app = await appClient.deploy({
onSchemaBreak: 'append',
onUpdate: 'append',
})
const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' })

// If app was just created fund the app account
if (['create', 'replace'].includes(app.operationPerformed)) {
if (['create', 'replace'].includes(result.operationPerformed)) {
await algorand.send.payment({
amount: algokit.algos(1),
amount: (1).algo(),
sender: deployer.addr,
receiver: app.appAddress,
receiver: appClient.appAddress,
})
}

const method = 'hello'
const response = await appClient.hello({ name: 'world' })
console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`)
const method = 'hello'
const response = await appClient.send.hello({
args: { name: 'world' },
})
console.log(
`Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from 'fs'
import * as path from 'path'
import { consoleLogger } from '@algorandfoundation/algokit-utils/types/logging'
import * as algokit from '@algorandfoundation/algokit-utils'
// import { registerDebugEventHandlers } from '@algorandfoundation/algokit-utils-debug' // Uncomment to enable persisting artifacts required by AlgoKit AVM Debugger

// Uncomment the debug and traceAll options to enable auto generation of AVM Debugger compliant sourceMap and simulation trace file.
// Learn more about using AlgoKit AVM Debugger to debug your TEAL source codes and inspect various kinds of Algorand transactions in atomic groups -> https://github.com/algorandfoundation/algokit-avm-vscode-Debugger
Expand All @@ -11,6 +12,7 @@ algokit.Config.configure({
// debug: true,
// traceAll: true,
})
// registerDebugEventHandlers() // Uncomment to enable persisting artifacts required by AlgoKit AVM Debugger

// base directory
const baseDir = path.resolve(__dirname)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { algorandFixture } from '@algorandfoundation/algokit-utils/testing'
import { HelloWorldClient } from '../smart_contracts/artifacts/hello_world/HelloWorldClient'
import { HelloWorldFactory } from '../smart_contracts/artifacts/hello_world/HelloWorldClient'
import { Account, Algodv2, Indexer } from 'algosdk'
import * as algokit from '@algorandfoundation/algokit-utils'
import { TransactionSignerAccount } from '@algorandfoundation/algokit-utils/types/account'

describe('hello world contract', () => {
const localnet = algorandFixture()
Expand All @@ -13,39 +14,36 @@ describe('hello world contract', () => {
})
beforeEach(localnet.beforeEach)

const deploy = async (account: Account, algod: Algodv2, indexer: Indexer) => {
const client = new HelloWorldClient(
{
resolveBy: 'creatorAndName',
findExistingUsing: indexer,
sender: account,
creatorAddress: account.addr,
},
algod,
)
await client.deploy({
onSchemaBreak: 'append',
onUpdate: 'append',
const deploy = async (account: Account & TransactionSignerAccount) => {
const factory = localnet.algorand.client.getTypedAppFactory(HelloWorldFactory, {
defaultSender: account.addr,
defaultSigner: account.signer,
})
return { client }

const { appClient } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' })
return { client: appClient }
}

test('says hello', async () => {
const { algod, indexer, testAccount } = localnet.context
const { client } = await deploy(testAccount, algod, indexer)
const { testAccount } = localnet.context
const { client } = await deploy(testAccount)

const result = await client.hello({ name: 'World' })
const result = await client.send.hello({ args: { name: 'World' } })

expect(result.return).toBe('Hello, World')
})

test('simulate says hello with correct budget consumed', async () => {
const { algod, indexer, testAccount } = localnet.context
const { client } = await deploy(testAccount, algod, indexer)
const result = await client.compose().hello({ name: 'World' }).hello({ name: 'Jane' }).simulate()
const { testAccount } = localnet.context
const { client } = await deploy(testAccount)
const result = await client
.newGroup()
.hello({ args: { name: 'World' } })
.hello({ args: { name: 'Jane' } })
.simulate()

expect(result.methodResults[0].returnValue).toBe('Hello, World')
expect(result.methodResults[1].returnValue).toBe('Hello, Jane')
expect(result.returns[0]).toBe('Hello, World')
expect(result.returns[1]).toBe('Hello, Jane')
expect(result.simulateResponse.txnGroups[0].appBudgetConsumed).toBeLessThan(100)
})
})
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import * as algokit from '@algorandfoundation/algokit-utils'
import { {{ contract_name.split('_')|map('capitalize')|join }}Client } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client'
import { {{ contract_name.split('_')|map('capitalize')|join }}Factory } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client'

// Below is a showcase of various deployment options you can use in TypeScript Client
export async function deploy() {
console.log('=== Deploying {{ contract_name.split('_')|map('capitalize')|join }} ===')

const algorand = algokit.AlgorandClient.fromEnvironment()
const deployer = await algorand.account.fromEnvironment('DEPLOYER')

const appClient = algorand.client.getTypedAppClientByCreatorAndName({{ contract_name.split('_')|map('capitalize')|join }}Client, {
sender: deployer,
creatorAddress: deployer.addr,
})

const app = await appClient.deploy({
onSchemaBreak: 'append',
onUpdate: 'append',
const factory = algorand.client.getTypedAppFactory({{ contract_name.split('_')|map('capitalize')|join }}Factory, {
defaultSender: deployer.addr,
})

const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' })

// If app was just created fund the app account
if (['create', 'replace'].includes(app.operationPerformed)) {
if (['create', 'replace'].includes(result.operationPerformed)) {
await algorand.send.payment({
amount: algokit.algos(1),
amount: (1).algo(),
sender: deployer.addr,
receiver: app.appAddress,
})
}

const method = 'hello'
const response = await appClient.hello({ name: 'world' })
console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`)
const method = 'hello'
const response = await appClient.send.hello({
args: { name: 'world' },
})
console.log(
`Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from 'fs'
import * as path from 'path'
import { consoleLogger } from '@algorandfoundation/algokit-utils/types/logging'
import * as algokit from '@algorandfoundation/algokit-utils'
// import { registerDebugEventHandlers } from '@algorandfoundation/algokit-utils-debug' // Uncomment to enable persisting artifacts required by AlgoKit AVM Debugger

// Uncomment the debug and traceAll options to enable auto generation of AVM Debugger compliant sourceMap and simulation trace file.
// Learn more about using AlgoKit AVM Debugger to debug your TEAL source codes and inspect various kinds of Algorand transactions in atomic groups -> https://github.com/algorandfoundation/algokit-avm-vscode-Debugger
Expand All @@ -11,6 +12,7 @@ algokit.Config.configure({
// debug: true,
// traceAll: true,
})
// registerDebugEventHandlers() // Uncomment to enable persisting artifacts required by AlgoKit AVM Debugger

// base directory
const baseDir = path.resolve(__dirname)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as algokit from '@algorandfoundation/algokit-utils'
import { {{ contract_name.split('_')|map('capitalize')|join }}Client } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client'
import { {{ contract_name.split('_')|map('capitalize')|join }}Factory } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client'

// Below is a showcase of various deployment options you can use in TypeScript Client
export async function deploy() {
Expand All @@ -8,26 +8,26 @@ export async function deploy() {
const algorand = algokit.AlgorandClient.fromEnvironment()
const deployer = await algorand.account.fromEnvironment('DEPLOYER')

const appClient = algorand.client.getTypedAppClientByCreatorAndName({% include pathjoin('includes', 'contract_name_pascal.jinja') %}Client, {
sender: deployer,
creatorAddress: deployer.addr,
const factory = algorand.client.getTypedAppFactory({{ contract_name.split('_')|map('capitalize')|join }}Factory, {
defaultSender: deployer.addr,
})

const app = await appClient.deploy({
onSchemaBreak: 'append',
onUpdate: 'append',
})
const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' })

// If app was just created fund the app account
if (['create', 'replace'].includes(app.operationPerformed)) {
if (['create', 'replace'].includes(result.operationPerformed)) {
await algorand.send.payment({
amount: algokit.algos(1),
amount: (1).algo(),
sender: deployer.addr,
receiver: app.appAddress,
receiver: appClient.appAddress,
})
}

const method = 'hello'
const response = await appClient.hello({ name: 'world' })
console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`)
const method = 'hello'
const response = await appClient.send.hello({
args: { name: 'world' },
})
console.log(
`Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"npm": ">=9.0"
},
"dependencies": {
"@algorandfoundation/algokit-utils": "^6.0.2",
"@algorandfoundation/algokit-utils": "7.0.0-beta.14",
"@algorandfoundation/algokit-utils-debug": "v1.0.2-beta.2",
"algosdk": "^2.7.0"
},
"devDependencies": {
"@algorandfoundation/algokit-client-generator": "^3.0.3",
"@algorandfoundation/algokit-client-generator": "v4.0.0-beta.5",
{%- if use_typescript_jest %}
"@types/jest": "^29.5.11",
{%- endif %}
Expand Down
Loading

0 comments on commit 60700af

Please sign in to comment.