Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
chore: add algosdk as a dependency (#41)
Browse files Browse the repository at this point in the history
* chore: add algosdk as a dependency

* chore: fixed the version

* tests: adding the algosdk in tests

* build: bumping dependencies

* build: updating test artifacts

* chore: adding engines field specifying node >= 18

* fix: fixing unit tests; removing deprecated algokit method

---------

Co-authored-by: Altynbek Orumbayev <[email protected]>
  • Loading branch information
negar-abbasi and aorumbayev authored Sep 4, 2023
1 parent b7f76dc commit 1fdb91d
Show file tree
Hide file tree
Showing 47 changed files with 591 additions and 449 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ export async function deploy() {

const algod = algokit.getAlgoClient()
const indexer = algokit.getAlgoIndexerClient()
const deployer = await algokit.getAccount(
{ config: algokit.getAccountConfigFromEnvironment('DEPLOYER'), fundWith: algokit.algos(3) },
algod,
)
const deployer = await algokit.mnemonicAccountFromEnvironment({ name: 'DEPLOYER', fundWith: algokit.algos(3) }, algod)
await algokit.ensureFunded(
{
accountToFund: deployer,
Expand All @@ -20,7 +17,6 @@ export async function deploy() {
},
algod,
)
const isMainNet = await algokit.isMainNet(algod)
const appClient = new {{ contract_name.split('_')|map('capitalize')|join }}Client(
{
resolveBy: 'creatorAndName',
Expand All @@ -37,6 +33,7 @@ export async function deploy() {
onUpdate: 'append',
})
{% elif preset_name == 'production' %}
const isMainNet = await algokit.isMainNet(algod)
const app = await appClient.deploy({
allowDelete: !isMainNet,
allowUpdate: !isMainNet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ export async function deploy() {

const algod = algokit.getAlgoClient()
const indexer = algokit.getAlgoIndexerClient()
const deployer = await algokit.getAccount(
{ config: algokit.getAccountConfigFromEnvironment('DEPLOYER'), fundWith: algokit.algos(3) },
algod,
)
const deployer = await algokit.mnemonicAccountFromEnvironment({ name: 'DEPLOYER', fundWith: algokit.algos(3) }, algod)
await algokit.ensureFunded(
{
accountToFund: deployer,
Expand All @@ -19,7 +16,6 @@ export async function deploy() {
},
algod,
)
const isMainNet = await algokit.isMainNet(algod)
const appClient = new {{ contract_name.split('_')|map('capitalize')|join }}Client(
{
resolveBy: 'creatorAndName',
Expand All @@ -36,6 +32,7 @@ export async function deploy() {
onUpdate: 'append',
})
{% elif preset_name == 'production' %}
const isMainNet = await algokit.isMainNet(algod)
const app = await appClient.deploy({
allowDelete: !isMainNet,
allowUpdate: !isMainNet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
"deploy:ci": "ts-node --transpile-only -r dotenv/config smart_contracts/index.ts",
"format": "prettier --write ."
},
"engines": {
"node": ">=18.0"
},
"dependencies": {
"@algorandfoundation/algokit-utils": "^2.3.1"
"@algorandfoundation/algokit-utils": "^3.0.0",
"algosdk": "^2.5.0"
},
"devDependencies": {
"dotenv": "^16.0.3",
Expand Down
18 changes: 16 additions & 2 deletions tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,14 @@ def test_smart_contract_generator_default_starter_preset(
) -> None:
test_name = f"test_smart_contract_generator_default_starter_preset_{language}"

response = run_init(working_dir, test_name)
response = run_init(
working_dir,
test_name,
answers={
"preset_name": "starter",
"deployment_language": language,
},
)
assert response.returncode == 0, response.stdout

response = run_generator(
Expand All @@ -203,7 +210,14 @@ def test_smart_contract_generator_default_production_preset(
) -> None:
test_name = f"test_smart_contract_generator_default_production_preset_{language}"

response = run_init(working_dir, test_name, answers={"preset_name": "production"})
response = run_init(
working_dir,
test_name,
answers={
"preset_name": "production",
"deployment_language": language,
},
)
assert response.returncode == 0, response.stdout

response = run_generator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
"deploy:ci": "ts-node --transpile-only -r dotenv/config smart_contracts/index.ts",
"format": "prettier --write ."
},
"engines": {
"node": ">=18.0"
},
"dependencies": {
"@algorandfoundation/algokit-utils": "^2.3.1"
"@algorandfoundation/algokit-utils": "^3.0.0",
"algosdk": "^2.5.0"
},
"devDependencies": {
"dotenv": "^16.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ export async function deploy() {

const algod = algokit.getAlgoClient()
const indexer = algokit.getAlgoIndexerClient()
const deployer = await algokit.getAccount(
{ config: algokit.getAccountConfigFromEnvironment('DEPLOYER'), fundWith: algokit.algos(3) },
algod,
)
const deployer = await algokit.mnemonicAccountFromEnvironment({ name: 'DEPLOYER', fundWith: algokit.algos(3) }, algod)
await algokit.ensureFunded(
{
accountToFund: deployer,
Expand All @@ -19,7 +16,6 @@ export async function deploy() {
},
algod,
)
const isMainNet = await algokit.isMainNet(algod)
const appClient = new HelloWorldClient(
{
resolveBy: 'creatorAndName',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
min_version = "v1.4.0"

[deploy]
command = "poetry run python -m smart_contracts deploy"
command = "npm run deploy:ci"
environment_secrets = [
"DEPLOYER_MNEMONIC",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as algokit from '@algorandfoundation/algokit-utils'
import { {{ contract_name.split('_')|map('capitalize')|join }}Client } from '../artifacts/{{ contract_name }}/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 algod = algokit.getAlgoClient()
const indexer = algokit.getAlgoIndexerClient()
const deployer = await algokit.mnemonicAccountFromEnvironment({ name: 'DEPLOYER', fundWith: algokit.algos(3) }, algod)
await algokit.ensureFunded(
{
accountToFund: deployer,
minSpendingBalance: algokit.algos(2),
minFundingIncrement: algokit.algos(2),
},
algod,
)
const appClient = new {{ contract_name.split('_')|map('capitalize')|join }}Client(
{
resolveBy: 'creatorAndName',
findExistingUsing: indexer,
sender: deployer,
creatorAddress: deployer.addr,
},
algod,
)

{%- if preset_name == 'starter' %}
const app = await appClient.deploy({
onSchemaBreak: 'append',
onUpdate: 'append',
})
{% elif preset_name == 'production' %}
const isMainNet = await algokit.isMainNet(algod)
const app = await appClient.deploy({
allowDelete: !isMainNet,
allowUpdate: !isMainNet,
onSchemaBreak: isMainNet ? 'append' : 'replace',
onUpdate: isMainNet ? 'append' : 'update',
})
{% endif %}

// If app was just created fund the app account
if (['create', 'replace'].includes(app.operationPerformed)) {
algokit.transferAlgos(
{
amount: algokit.algos(1),
from: deployer,
to: app.appAddress,
},
algod,
)
}

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}`)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ algod_token: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
author_email: None
author_name: None
contract_name: hello_world
deployment_language: python
deployment_language: typescript
ide_vscode: true
indexer_port: 8980
indexer_server: http://localhost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ jobs:
git diff --exit-code --minimal ./smart_contracts/artifacts || (echo "::error ::Smart contract artifacts have changed, ensure committed artifacts are up to date" && exit 1);
- name: Run deployer against LocalNet
run: poetry run python -m smart_contracts deploy
run: npm run --prefix smart_contracts deploy:ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# don't ever format node_modules
node_modules
# don't lint format output (make sure it's set to your correct build folder name)
dist
build
# don't format nyc coverage output
coverage
# don't format generated types
**/generated/types.d.ts
**/generated/types.ts
# don't format ide files
.idea
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
singleQuote: true,
jsxSingleQuote: false,
semi: false,
tabWidth: 2,
trailingComma: 'all',
printWidth: 120,
endOfLine: 'lf',
arrowParens: 'always',
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"ms-python.python",
"charliermarsh.ruff",
"matangover.mypy",
"esbenp.prettier-vscode",
"bungcip.better-toml",
"editorconfig.editorconfig"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
"configurations": [
{
"name": "Build & Deploy Beaker application",
"type": "python",
"type": "node",
"request": "launch",
"module": "smart_contracts",
"cwd": "${workspaceFolder}",
"preLaunchTask": "Start AlgoKit LocalNet",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "deploy"],
"cwd": "${workspaceFolder}/smart_contracts",
"console": "integratedTerminal",
"skipFiles": ["<node_internals>/**", "node_modules/**"],
"preLaunchTask": "Build Beaker application (+ LocalNet)",
"envFile": "${workspaceFolder}/.env.localnet"
},
{
"name": "Deploy Built Beaker application",
"type": "python",
"type": "node",
"request": "launch",
"module": "smart_contracts",
"args": ["deploy"],
"cwd": "${workspaceFolder}",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "deploy"],
"cwd": "${workspaceFolder}/smart_contracts",
"console": "integratedTerminal",
"skipFiles": ["<node_internals>/**", "node_modules/**"],
"envFile": "${workspaceFolder}/.env.localnet"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
".idea": true
},

// TypeScript
"editor.defaultFormatter": "esbenp.prettier-vscode",

// Python
"python.analysis.extraPaths": ["${workspaceFolder}/smart_contracts"],
"python.defaultInterpreterPath": "${workspaceFolder}/.venv",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ This project has been generated using AlgoKit. See below for default getting sta
- Run `poetry install` in the root directory, which will set up a `.venv` folder with a Python virtual environment and also install all Python dependencies
- Copy `.env.template` to `.env`
- Run `algokit localnet start` to start a local Algorand network in Docker. If you are using VS Code launch configurations provided by the template, this will be done automatically for you.
- Run `npm install` to install NPM packages

3. Open the project and start debugging / developing via:
- VS Code
1. Open the repository root in VS Code
Expand Down Expand Up @@ -46,9 +48,9 @@ This project uses [GitHub Actions](https://docs.github.com/en/actions/learn-gith
#### Setting up GitHub for CI/CD workflow and TestNet deployment

1. Every time you have a change to your smart contract, and when you first initialize the project you need to [build the contract](#initial-setup) and then commit the `smart_contracts/artifacts` folder so the [output stability](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/articles/output_stability.md) tests pass
2. Decide what values you want to use for the `allow_update`, `allow_delete` and the `on_schema_break`, `on_update` parameters specified in [`contract.py`](./smart_contracts/hello_world/contract.py).
When deploying to LocalNet these values are both set to allow update and replacement of the app for convenience. But for non-LocalNet networks
the defaults are more conservative.
2. Decide what values you want to use for the `allowUpdate` and `allowDelete` parameters specified in [`deploy-config.ts`](./smart_contracts/hello_world/deploy-config.ts).
When deploying to LocalNet these values are both set to `true` for convenience. But for non-LocalNet networks
they are more conservative and use `false`
These default values will allow the smart contract to be deployed initially, but will not allow the app to be updated or deleted if is changed and the build will instead fail.
To help you decide it may be helpful to read the [AlgoKit Utils app deployment documentation](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/docs/capabilities/app-deploy.md) or the [AlgoKit smart contract deployment architecture](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/architecture-decisions/2023-01-12_smart-contract-deployment.md#upgradeable-and-deletable-contracts).
3. Create a [Github Environment](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#creating-an-environment) named `Test`.
Expand Down Expand Up @@ -88,12 +90,16 @@ This project makes use of Python to build Algorand smart contracts. The followin
- [AlgoKit](https://github.com/algorandfoundation/algokit-cli) - One-stop shop tool for developers building on the Algorand network; [docs](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/algokit.md), [intro tutorial](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/tutorials/intro.md)
- [Beaker](https://github.com/algorand-devrel/beaker) - Smart contract development framework for PyTeal; [docs](https://beaker.algo.xyz), [examples](https://github.com/algorand-devrel/beaker/tree/master/examples)
- [PyTEAL](https://github.com/algorand/pyteal) - Python language binding for Algorand smart contracts; [docs](https://pyteal.readthedocs.io/en/stable/)
- [AlgoKit Utils](https://github.com/algorandfoundation/algokit-utils-py) - A set of core Algorand utilities that make it easier to build solutions on Algorand.
- [AlgoKit Utils](https://github.com/algorandfoundation/algokit-utils-ts) - A set of core Algorand utilities that make it easier to build solutions on Algorand.
- [Poetry](https://python-poetry.org/): Python packaging and dependency management.- [Black](https://github.com/psf/black): A Python code formatter.- [Ruff](https://github.com/charliermarsh/ruff): An extremely fast Python linter.

- [mypy](https://mypy-lang.org/): Static type checker.
- [pytest](https://docs.pytest.org/): Automated testing.
- [pip-audit](https://pypi.org/project/pip-audit/): Tool for scanning Python environments for packages with known vulnerabilities.
- [pre-commit](https://pre-commit.com/): A framework for managing and maintaining multi-language pre-commit hooks, to enable pre-commit you need to run `pre-commit install` in the root of the repository. This will install the pre-commit hooks and run them against modified files when committing. If any of the hooks fail, the commit will be aborted. To run the hooks on all files, use `pre-commit run --all-files`.
- [npm](https://www.npmjs.com/): Node.js package manager
- [TypeScript](https://www.typescriptlang.org/): Strongly typed programming language that builds on JavaScript
- [ts-node-dev](https://github.com/wclr/ts-node-dev): TypeScript development execution environment

It has also been configured to have a productive dev experience out of the box in [VS Code](https://code.visualstudio.com/), see the [.vscode](./.vscode) folder.

Loading

0 comments on commit 1fdb91d

Please sign in to comment.