From f921b91252c0d9fa7df2cab4cda7dcaf8dc75389 Mon Sep 17 00:00:00 2001 From: Cheng Wang Date: Wed, 16 Oct 2024 10:55:46 +0200 Subject: [PATCH 1/3] Clean templates --- packages/cli/.editorconfig | 13 -- packages/cli/.eslintignore | 2 - packages/cli/.gitattributes | 1 - packages/cli/.gitignore | 7 - packages/cli/contracts/greeter/greeter.ral | 6 - .../contracts/greeter/greeter_interface.ral | 3 - packages/cli/contracts/greeter_main.ral | 7 - packages/cli/devnet-user.conf | 53 ------- packages/cli/jest-config.json | 17 --- packages/cli/templates/base/.eslintrc.json | 16 -- packages/cli/templates/base/README.md | 25 --- .../cli/templates/base/alephium.config.ts | 50 ------ .../cli/templates/base/contracts/token.ral | 69 --------- .../cli/templates/base/contracts/withdraw.ral | 8 - packages/cli/templates/base/package.json | 48 ------ .../templates/base/scripts/0_deploy_faucet.ts | 30 ---- packages/cli/templates/base/src/token.ts | 48 ------ .../cli/templates/base/test/token.test.ts | 142 ------------------ packages/cli/templates/react/.eslintrc.json | 16 -- packages/cli/templates/react/README.md | 34 ----- .../cli/templates/react/config-overrides.js | 19 --- packages/cli/templates/react/package.json | 63 -------- packages/cli/templates/react/src/App.tsx | 42 ------ .../react/src/artifacts/Greeter.ral.json | 34 ----- .../react/src/artifacts/GreeterMain.ral.json | 28 ---- packages/cli/templates/shared/tsconfig.json | 21 --- 26 files changed, 802 deletions(-) delete mode 100644 packages/cli/.editorconfig delete mode 100644 packages/cli/.eslintignore delete mode 100644 packages/cli/.gitattributes delete mode 100644 packages/cli/.gitignore delete mode 100644 packages/cli/contracts/greeter/greeter.ral delete mode 100644 packages/cli/contracts/greeter/greeter_interface.ral delete mode 100644 packages/cli/contracts/greeter_main.ral delete mode 100644 packages/cli/devnet-user.conf delete mode 100644 packages/cli/jest-config.json delete mode 100644 packages/cli/templates/base/.eslintrc.json delete mode 100644 packages/cli/templates/base/README.md delete mode 100644 packages/cli/templates/base/alephium.config.ts delete mode 100644 packages/cli/templates/base/contracts/token.ral delete mode 100644 packages/cli/templates/base/contracts/withdraw.ral delete mode 100644 packages/cli/templates/base/package.json delete mode 100644 packages/cli/templates/base/scripts/0_deploy_faucet.ts delete mode 100644 packages/cli/templates/base/src/token.ts delete mode 100644 packages/cli/templates/base/test/token.test.ts delete mode 100644 packages/cli/templates/react/.eslintrc.json delete mode 100644 packages/cli/templates/react/README.md delete mode 100644 packages/cli/templates/react/config-overrides.js delete mode 100644 packages/cli/templates/react/package.json delete mode 100644 packages/cli/templates/react/src/App.tsx delete mode 100644 packages/cli/templates/react/src/artifacts/Greeter.ral.json delete mode 100644 packages/cli/templates/react/src/artifacts/GreeterMain.ral.json delete mode 100644 packages/cli/templates/shared/tsconfig.json diff --git a/packages/cli/.editorconfig b/packages/cli/.editorconfig deleted file mode 100644 index 7733358e8..000000000 --- a/packages/cli/.editorconfig +++ /dev/null @@ -1,13 +0,0 @@ -# EditorConfig is awesome: https://EditorConfig.org -root = true - -[*] -charset = utf-8 -end_of_line = lf -indent_style = space -indent_size = 2 -insert_final_newline = true -trim_trailing_whitespace = false - -[*.ral] -indent_size = 4 diff --git a/packages/cli/.eslintignore b/packages/cli/.eslintignore deleted file mode 100644 index feeccda09..000000000 --- a/packages/cli/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -**/dist/ -**/templates/ diff --git a/packages/cli/.gitattributes b/packages/cli/.gitattributes deleted file mode 100644 index 331025ba2..000000000 --- a/packages/cli/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*.ral linguist-language=Rust diff --git a/packages/cli/.gitignore b/packages/cli/.gitignore deleted file mode 100644 index 3d36ace15..000000000 --- a/packages/cli/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -node_modules/ -coverage/ -lerna-debug.log -/dist -/dev -.deployments.devnet.json -.ralph-lsp/ diff --git a/packages/cli/contracts/greeter/greeter.ral b/packages/cli/contracts/greeter/greeter.ral deleted file mode 100644 index d77193f38..000000000 --- a/packages/cli/contracts/greeter/greeter.ral +++ /dev/null @@ -1,6 +0,0 @@ -Contract Greeter(btcPrice: U256) implements GreeterInterface { - pub fn greet() -> U256 { - checkCaller!(true, 0) - return btcPrice - } -} diff --git a/packages/cli/contracts/greeter/greeter_interface.ral b/packages/cli/contracts/greeter/greeter_interface.ral deleted file mode 100644 index 6a74713f0..000000000 --- a/packages/cli/contracts/greeter/greeter_interface.ral +++ /dev/null @@ -1,3 +0,0 @@ -Interface GreeterInterface { - pub fn greet() -> U256 -} diff --git a/packages/cli/contracts/greeter_main.ral b/packages/cli/contracts/greeter_main.ral deleted file mode 100644 index 364dec468..000000000 --- a/packages/cli/contracts/greeter_main.ral +++ /dev/null @@ -1,7 +0,0 @@ -TxScript GreeterMain(greeterContractId: ByteVec) { - let greeter0 = Greeter(greeterContractId) - assert!(greeter0.greet() == 1, 0) - - let greeter1 = GreeterInterface(greeterContractId) - assert!(greeter1.greet() == 1, 0) -} diff --git a/packages/cli/devnet-user.conf b/packages/cli/devnet-user.conf deleted file mode 100644 index be7916195..000000000 --- a/packages/cli/devnet-user.conf +++ /dev/null @@ -1,53 +0,0 @@ -// in most cases, modify the following genesis allocations -alephium.genesis.allocations = [ - { - address = "1DrDyTr9RpRsQnDnXo2YRiPzPW4ooHX5LLoqXrqfMrpQH", - amount = 1000000000000000000000000, - lock-duration = 0 seconds - }, - { - address = "14UAjZ3qcmEVKdTo84Kwf4RprTQi86w2TefnnGFjov9xF", - amount = 1000000000000000000000000, - lock-duration = 0 seconds - }, - { - address = "15jjExDyS8q3Wqk9v29PCQ21jDqubDrD8WQdgn6VW2oi4", - amount = 1000000000000000000000000, - lock-duration = 0 seconds - }, - { - address = "17cBiTcWhung3WDLuc9ja5Y7BMus5Q7CD9wYBxS1r1P2R", - amount = 1000000000000000000000000, - lock-duration = 0 seconds - } -] // 1 million token allocated for your address -alephium.consensus.num-zeros-at-least-in-hash = 0 -alephium.consensus.block-target-time = 10 millis -alephium.consensus.uncle-dependency-gap-time = 0 seconds -alephium.network.leman-hard-fork-timestamp = 1643500800000 // GMT: 30 January 2022 00:00:00 - -alephium.network.network-id = 4 -alephium.discovery.bootstrap = [] -alephium.wallet.locking-timeout = 99999 minutes -alephium.mempool.auto-mine-for-dev = true -alephium.node.event-log.enabled=true -alephium.node.event-log.index-by-tx-id = true -alephium.node.event-log.index-by-block-hash = true - -alephium.network.rest-port = 22973 -alephium.network.ws-port = 21973 -alephium.network.miner-api-port = 20973 -alephium.api.network-interface = "0.0.0.0" -alephium.api.api-key-enabled = false -alephium.mining.api-interface = "0.0.0.0" -alephium.network.bind-address = "0.0.0.0:19973" -alephium.network.internal-address = "127.0.0.1:19973" -alephium.network.coordinator-address = "127.0.0.1:19973" - -// arbitrary mining addresses -alephium.mining.miner-addresses = [ -"1FsroWmeJPBhcPiUr37pWXdojRBe6jdey9uukEXk1TheA", -"1CQvSXsmM5BMFKguKDPpNUfw1idiut8UifLtT8748JdHc", -"193maApeJWrz9GFwWCfa982ccLARVE9Y1WgKSJaUs7UAx", -"16fZKYPCZJv2TP3FArA9FLUQceTS9U8xVnSjxFG9MBKyY" -] diff --git a/packages/cli/jest-config.json b/packages/cli/jest-config.json deleted file mode 100644 index 4180b1958..000000000 --- a/packages/cli/jest-config.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "testPathIgnorePatterns": [".*/node_modules/", ".*/templates/.*"], - "transform": { - "^.+\\.(t|j)sx?$": "ts-jest" - }, - "testMatch": ["**/(src|test)/**/*.test.ts"], - "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"], - "collectCoverage": true, - "coverageDirectory": "./coverage/", - "collectCoverageFrom": [ - "packages/*/src/**/*.ts", - "!packages/web3-react/src/**/*.ts" - ], - "moduleDirectories": [ - "node_modules" - ] -} diff --git a/packages/cli/templates/base/.eslintrc.json b/packages/cli/templates/base/.eslintrc.json deleted file mode 100644 index ef77658de..000000000 --- a/packages/cli/templates/base/.eslintrc.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": [ - "prettier", - "plugin:prettier/recommended", - "plugin:@typescript-eslint/recommended" - ], - "rules": { - "header/header": ["off"] - }, - "parserOptions": { - "project": "tsconfig.json", - "ecmaVersion": 2020, - "sourceType": "module" - }, - "parser": "@typescript-eslint/parser" -} diff --git a/packages/cli/templates/base/README.md b/packages/cli/templates/base/README.md deleted file mode 100644 index d420c39e2..000000000 --- a/packages/cli/templates/base/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# My dApp Template - -## Install - -``` -npm install -``` - -## Start a local devnet for testing and development - -Please refer to the documentation here: https://wiki.alephium.org/full-node/devnet - -## Compile - -Compile the TypeScript files into JavaScript: - -``` -npx @alephium/cli@latest compile -``` - -## Testing - -``` -npx @alephium/cli@latest test -``` diff --git a/packages/cli/templates/base/alephium.config.ts b/packages/cli/templates/base/alephium.config.ts deleted file mode 100644 index f9f293688..000000000 --- a/packages/cli/templates/base/alephium.config.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Configuration } from '@alephium/cli' -import { Number256 } from '@alephium/web3' - -// Settings are usually for configuring -export type Settings = { - issueTokenAmount: Number256 - openaiAPIKey?: string - ipfs?: { - infura?: { - projectId: string, - projectSecret: string - } - } -} - -const defaultSettings: Settings = { - issueTokenAmount: 100n, - openaiAPIKey: process.env.OPENAI_API_KEY || '', - ipfs: { - infura: { - projectId: process.env.IPFS_INFURA_PROJECT_ID || '', - projectSecret: process.env.IPFS_INFURA_PROJECT_SECRET || '' - } - } -} - -const configuration: Configuration = { - networks: { - devnet: { - nodeUrl: 'http://127.0.0.1:22973', - // here we could configure which address groups to deploy the contract - privateKeys: ['a642942e67258589cd2b1822c631506632db5a12aabcf413604e785300d762a5'], - settings: defaultSettings - }, - - testnet: { - nodeUrl: process.env.NODE_URL as string, - privateKeys: process.env.PRIVATE_KEYS === undefined ? [] : process.env.PRIVATE_KEYS.split(','), - settings: defaultSettings - }, - - mainnet: { - nodeUrl: process.env.NODE_URL as string, - privateKeys: process.env.PRIVATE_KEYS === undefined ? [] : process.env.PRIVATE_KEYS.split(','), - settings: defaultSettings - } - } -} - -export default configuration diff --git a/packages/cli/templates/base/contracts/token.ral b/packages/cli/templates/base/contracts/token.ral deleted file mode 100644 index 580e5b568..000000000 --- a/packages/cli/templates/base/contracts/token.ral +++ /dev/null @@ -1,69 +0,0 @@ -import "std/fungible_token_interface" - -// Defines a contract named `TokenFaucet`. -// A contract is a collection of fields (its state) and functions. -// Once deployed, a contract resides at a specific address on the Alephium blockchain. -// Contract fields are permanently stored in contract storage. -// A contract can issue an initial amount of token at its deployment. -Contract TokenFaucet( - symbol: ByteVec, - name: ByteVec, - decimals: U256, - supply: U256, - mut balance: U256 -) implements IFungibleToken { - - // Events allow for logging of activities on the blockchain. - // Alephium clients can listen to events in order to react to contract state changes. - event Withdraw(to: Address, amount: U256) - - enum ErrorCodes { - InvalidWithdrawAmount = 0 - } - - // A public function that returns the initial supply of the contract's token. - // Note that the field must be initialized as the amount of the issued token. - pub fn getTotalSupply() -> U256 { - return supply - } - - // A public function that returns the symbol of the token. - pub fn getSymbol() -> ByteVec { - return symbol - } - - // A public function that returns the name of the token. - pub fn getName() -> ByteVec { - return name - } - - // A public function that returns the decimals of the token. - pub fn getDecimals() -> U256 { - return decimals - } - - // A public function that returns the current balance of the contract. - pub fn balance() -> U256 { - return balance - } - - // A public function that transfers tokens to anyone who calls it. - // The function is annotated with `updateFields = true` as it changes the contract fields. - // The function is annotated as using contract assets as it does. - // The function is annotated with `checkExternalCaller = false` as there is no need to check the external caller. - @using(assetsInContract = true, updateFields = true, checkExternalCaller = false) - pub fn withdraw(amount: U256) -> () { - // Debug events can be helpful for error analysis - emit Debug(`The current balance is ${balance}`) - - // Make sure the amount is valid - assert!(amount <= 2, ErrorCodes.InvalidWithdrawAmount) - // Functions postfixed with `!` are built-in functions. - transferTokenFromSelf!(callerAddress!(), selfTokenId!(), amount) - // Ralph does not allow underflow. - balance = balance - amount - - // Emit the event defined earlier. - emit Withdraw(callerAddress!(), amount) - } -} diff --git a/packages/cli/templates/base/contracts/withdraw.ral b/packages/cli/templates/base/contracts/withdraw.ral deleted file mode 100644 index c54ba1a13..000000000 --- a/packages/cli/templates/base/contracts/withdraw.ral +++ /dev/null @@ -1,8 +0,0 @@ -// Defines a transaction script. -// A transaction script is a piece of code to interact with contracts on the blockchain. -// Transaction scripts can use the input assets of transactions in general. -// A script is disposable and will only be executed once along with the holder transaction. -TxScript Withdraw(token: TokenFaucet, amount: U256) { - // Call token contract's withdraw function. - token.withdraw(amount) -} diff --git a/packages/cli/templates/base/package.json b/packages/cli/templates/base/package.json deleted file mode 100644 index 786cceee0..000000000 --- a/packages/cli/templates/base/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "my-dapp-template", - "version": "0.1.0", - "license": "GPL", - "scripts": { - "build": "npm run clean && npx --yes tsc --build .", - "clean": "npm run clean:windows && npm run clean:unix", - "clean:unix": "node -e \"if (process.platform !== 'win32') process.exit(1)\" || rm -rf dist", - "clean:windows": "node -e \"if (process.platform === 'win32') process.exit(1)\" || , if exist dist rmdir /Q /S dist", - "compile": "npx cli compile", - "deploy": "npx cli deploy", - "lint": "eslint . --ext ts", - "lint:fix": "eslint . --fix --ext ts", - "test": "jest -i --config ./jest-config.json" - }, - "dependencies": { - "@alephium/cli": "^1.8.0", - "@alephium/web3": "^1.8.0", - "@alephium/web3-test": "^1.8.0", - "@alephium/web3-wallet": "^1.8.0" - }, - "devDependencies": { - "@types/jest": "^27.5.1", - "@types/node": "^16.18.23", - "@typescript-eslint/eslint-plugin": "^5.57.0", - "@typescript-eslint/parser": "^5.57.0", - "eslint": "^8.37.0", - "eslint-config-prettier": "^8.5.0", - "eslint-plugin-prettier": "^4.0.0", - "jest": "^28.1.0", - "ts-jest": "^28.0.2", - "ts-node": "^10.7.0", - "typescript": "^4.4.2" - }, - "engines": { - "node": ">=14.0.0", - "npm": ">=7.0.0" - }, - "prettier": { - "printWidth": 120, - "tabWidth": 2, - "useTabs": false, - "semi": false, - "singleQuote": true, - "bracketSameLine": false, - "trailingComma": "none" - } -} diff --git a/packages/cli/templates/base/scripts/0_deploy_faucet.ts b/packages/cli/templates/base/scripts/0_deploy_faucet.ts deleted file mode 100644 index 389ae2d2b..000000000 --- a/packages/cli/templates/base/scripts/0_deploy_faucet.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Deployer, DeployFunction, Network } from '@alephium/cli' -import { Settings } from '../alephium.config' -import { TokenFaucet } from '../artifacts/ts' -import { stringToHex } from '@alephium/web3' - -// This deploy function will be called by cli deployment tool automatically -// Note that deployment scripts should prefixed with numbers (starting from 0) -const deployFaucet: DeployFunction = async ( - deployer: Deployer, - network: Network -): Promise => { - // Get settings - const issueTokenAmount = network.settings.issueTokenAmount - const result = await deployer.deployContract(TokenFaucet, { - // The amount of token to be issued - issueTokenAmount: issueTokenAmount, - // The initial states of the faucet contract - initialFields: { - symbol: stringToHex('TF'), - name: stringToHex('TokenFaucet'), - decimals: 18n, - supply: issueTokenAmount, - balance: issueTokenAmount - } - }) - console.log('Token faucet contract id: ' + result.contractInstance.contractId) - console.log('Token faucet contract address: ' + result.contractInstance.address) -} - -export default deployFaucet diff --git a/packages/cli/templates/base/src/token.ts b/packages/cli/templates/base/src/token.ts deleted file mode 100644 index 89643953e..000000000 --- a/packages/cli/templates/base/src/token.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { Deployments } from '@alephium/cli' -import { web3, DUST_AMOUNT } from '@alephium/web3' -import { testNodeWallet } from '@alephium/web3-test' -import configuration from '../alephium.config' -import { TokenFaucet } from '../artifacts/ts' - -async function withdraw() { - web3.setCurrentNodeProvider('http://127.0.0.1:22973') - - // Attention: test wallet is used for demonstration purpose - const signer = await testNodeWallet() - - const deployments = await Deployments.load(configuration, 'devnet') - - // The test wallet has four accounts with one in each address group - // The wallet calls withdraw function for all of the address groups - for (const account of await signer.getAccounts()) { - // Set an active account to prepare and sign transactions - await signer.setSelectedAccount(account.address) - const accountGroup = account.group - - // Load the metadata of the deployed contract in the right group - const faucet = deployments.getInstance(TokenFaucet, accountGroup) - if (faucet === undefined) { - console.log(`The contract is not deployed on group ${account.group}`) - continue - } - const tokenId = faucet.contractId - const tokenAddress = faucet.address - console.log(`Token faucet contract id: ${tokenId}`) - console.log(`Token faucet contract address: ${tokenAddress}`) - - // Submit a transaction to use the transaction script - await faucet.transact.withdraw({ - signer: signer, - attoAlphAmount: DUST_AMOUNT * 2n, - args: { - amount: 1n - }, - }) - - // Fetch the latest state of the token contract - const state = await faucet.fetchState() - console.log(JSON.stringify(state.fields, null, ' ')) - } -} - -withdraw() diff --git a/packages/cli/templates/base/test/token.test.ts b/packages/cli/templates/base/test/token.test.ts deleted file mode 100644 index b4eebe516..000000000 --- a/packages/cli/templates/base/test/token.test.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { web3, TestContractParams, addressFromContractId, AssetOutput, DUST_AMOUNT, enableDebugMode } from '@alephium/web3' -import { expectAssertionError, randomContractId, testAddress, testNodeWallet } from '@alephium/web3-test' -import { deployToDevnet } from '@alephium/cli' -import { TokenFaucet, TokenFaucetTypes } from '../artifacts/ts' - -describe('unit tests', () => { - let testContractId: string - let testTokenId: string - let testContractAddress: string - let testParamsFixture: TestContractParams - - // We initialize the fixture variables before all tests - beforeAll(async () => { - web3.setCurrentNodeProvider('http://127.0.0.1:22973', undefined, fetch) - testContractId = randomContractId() - testTokenId = testContractId - testContractAddress = addressFromContractId(testContractId) - testParamsFixture = { - // a random address that the test contract resides in the tests - address: testContractAddress, - // assets owned by the test contract before a test - initialAsset: { alphAmount: 10n ** 18n, tokens: [{ id: testTokenId, amount: 10n }] }, - // initial state of the test contract - initialFields: { - symbol: Buffer.from('TF', 'utf8').toString('hex'), - name: Buffer.from('TokenFaucet', 'utf8').toString('hex'), - decimals: 18n, - supply: 10n ** 18n, - balance: 10n - }, - // arguments to test the target function of the test contract - testArgs: { amount: 1n }, - // assets owned by the caller of the function - inputAssets: [{ address: testAddress, asset: { alphAmount: 10n ** 18n } }] - } - }) - - it('test withdraw', async () => { - const testParams = testParamsFixture - const testResult = await TokenFaucet.tests.withdraw(testParams) - - // only one contract involved in the test - const contractState = testResult.contracts[0] as TokenFaucetTypes.State - expect(contractState.address).toEqual(testContractAddress) - expect(contractState.fields.supply).toEqual(10n ** 18n) - // the balance of the test token is: 10 - 1 = 9 - expect(contractState.fields.balance).toEqual(9n) - // double check the balance of the contract assets - expect(contractState.asset).toEqual({ alphAmount: 10n ** 18n, tokens: [{ id: testTokenId, amount: 9n }] }) - - // three transaction outputs in total - expect(testResult.txOutputs.length).toEqual(3) - - // the first transaction output is for the token - const tokenOutput = testResult.txOutputs[0] as AssetOutput - expect(tokenOutput.type).toEqual('AssetOutput') - expect(tokenOutput.address).toEqual(testAddress) - expect(tokenOutput.alphAmount).toEqual(DUST_AMOUNT) // dust amount - // the caller withdrawn 1 token from the contract - expect(tokenOutput.tokens).toEqual([{ id: testTokenId, amount: 1n }]) - - // the second transaction output is for the ALPH - const alphOutput = testResult.txOutputs[1] as AssetOutput - expect(alphOutput.type).toEqual('AssetOutput') - expect(alphOutput.address).toEqual(testAddress) - expect(alphOutput.alphAmount).toBeLessThan(10n ** 18n) // the caller paid gas - expect(alphOutput.tokens).toEqual([]) - - // the third transaction output is for the contract - const contractOutput = testResult.txOutputs[2] - expect(contractOutput.type).toEqual('ContractOutput') - expect(contractOutput.address).toEqual(testContractAddress) - expect(contractOutput.alphAmount).toEqual(10n ** 18n) - // the contract has transferred 1 token to the caller - expect(contractOutput.tokens).toEqual([{ id: testTokenId, amount: 9n }]) - - // a `Withdraw` event is emitted when the test passes - expect(testResult.events.length).toEqual(1) - const event = testResult.events[0] as TokenFaucetTypes.WithdrawEvent - // the event is emitted by the test contract - expect(event.contractAddress).toEqual(testContractAddress) - // the name of the event is `Withdraw` - expect(event.name).toEqual('Withdraw') - // the first field of the event - expect(event.fields.to).toEqual(testAddress) - // the second field of the event - expect(event.fields.amount).toEqual(1n) - - // the test framework support debug messages too - // debug will be disabled automatically at the deployment to real networks - expect(testResult.debugMessages).toEqual([ - { contractAddress: testContractAddress, message: 'The current balance is 10' } - ]) - }) - - it('test withdraw', async () => { - const testParams = { ...testParamsFixture, testArgs: { amount: 3n } } - // test that assertion failed in the withdraw function - await expectAssertionError(TokenFaucet.tests.withdraw(testParams), testContractAddress, 0) - }) -}) - -describe('integration tests', () => { - beforeAll(async () => { - web3.setCurrentNodeProvider('http://127.0.0.1:22973', undefined, fetch) - }) - - it('should withdraw on devnet', async () => { - const signer = await testNodeWallet() - const deployments = await deployToDevnet() - - // Test with all of the addresses of the wallet - for (const account of await signer.getAccounts()) { - const testAddress = account.address - await signer.setSelectedAccount(testAddress) - const testGroup = account.group - - const faucet = deployments.getInstance(TokenFaucet, testGroup) - if (faucet === undefined) { - console.log(`The contract is not deployed on group ${account.group}`) - continue - } - - expect(faucet.groupIndex).toEqual(testGroup) - const initialState = await faucet.fetchState() - const initialBalance = initialState.fields.balance - - // Call `withdraw` function 10 times - for (let i = 0; i < 10; i++) { - await faucet.transact.withdraw({ - signer: signer, - attoAlphAmount: DUST_AMOUNT * 3n, - args: { amount: 1n } - }) - - const newState = await faucet.fetchState() - const newBalance = newState.fields.balance - expect(newBalance).toEqual(initialBalance - BigInt(i) - 1n) - } - } - }, 20000) -}) diff --git a/packages/cli/templates/react/.eslintrc.json b/packages/cli/templates/react/.eslintrc.json deleted file mode 100644 index ef77658de..000000000 --- a/packages/cli/templates/react/.eslintrc.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": [ - "prettier", - "plugin:prettier/recommended", - "plugin:@typescript-eslint/recommended" - ], - "rules": { - "header/header": ["off"] - }, - "parserOptions": { - "project": "tsconfig.json", - "ecmaVersion": 2020, - "sourceType": "module" - }, - "parser": "@typescript-eslint/parser" -} diff --git a/packages/cli/templates/react/README.md b/packages/cli/templates/react/README.md deleted file mode 100644 index 785b842dd..000000000 --- a/packages/cli/templates/react/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# My dApp - -## Install - -``` -npm install -``` - -## Start the app - -Compile the TypeScript files into JavaScript: - -``` -npm run start -``` - -## Start a devnet - -``` -npm run start-devnet // this will start a devnet for smart contract tests -``` - -## Stop/restart devnet - -``` -npm run stop-devnet -npm run restart-devnet -``` - -## Testing - -``` -npm test -``` diff --git a/packages/cli/templates/react/config-overrides.js b/packages/cli/templates/react/config-overrides.js deleted file mode 100644 index 2503fcc6c..000000000 --- a/packages/cli/templates/react/config-overrides.js +++ /dev/null @@ -1,19 +0,0 @@ -const webpack = require('webpack') - -module.exports = function override(config) { - const fallback = config.resolve.fallback || {} - Object.assign(fallback, { - fs: false, - crypto: require.resolve('crypto-browserify'), - stream: require.resolve('stream-browserify'), - path: require.resolve('path-browserify') - }) - config.resolve.fallback = fallback - config.plugins = (config.plugins || []).concat([ - new webpack.ProvidePlugin({ - process: 'process/browser', - Buffer: ['buffer', 'Buffer'] - }) - ]) - return config -} diff --git a/packages/cli/templates/react/package.json b/packages/cli/templates/react/package.json deleted file mode 100644 index 08f93946e..000000000 --- a/packages/cli/templates/react/package.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "name": "my-dapp", - "version": "0.1.0", - "dependencies": { - "@testing-library/jest-dom": "^5.16.4", - "@testing-library/react": "^13.0.1", - "@testing-library/user-event": "^13.5.0", - "@types/jest": "^27.4.1", - "@types/node": "^16.18.23", - "@types/react": "^18.0.3", - "@types/react-dom": "^18.0.0", - "@alephium/web3": "^1.8.0", - "react": "^18.0.0", - "react-dom": "^18.0.0", - "react-scripts": "5.0.1", - "typescript": "^4.6.3", - "web-vitals": "^2.1.4" - }, - "scripts": { - "start": "react-app-rewired start", - "build": "react-app-rewired build", - "test": "react-app-rewired test", - "eject": "react-scripts eject", - "lint": "eslint . --ext ts,tsx", - "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"" - }, - "eslintConfig": { - "extends": [ - "react-app", - "react-app/jest" - ] - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - }, - "devDependencies": { - "buffer": "^6.0.3", - "crypto-browserify": "^3.12.0", - "eslint-config-prettier": "^8.5.0", - "process": "^0.11.10", - "react-app-rewired": "^2.2.1", - "stream-browserify": "^3.0.0" - }, - "prettier": { - "printWidth": 120, - "tabWidth": 2, - "useTabs": false, - "semi": false, - "singleQuote": true, - "jsxSingleQuote": true, - "bracketSameLine": false, - "trailingComma": "none" - } -} diff --git a/packages/cli/templates/react/src/App.tsx b/packages/cli/templates/react/src/App.tsx deleted file mode 100644 index 4c601a239..000000000 --- a/packages/cli/templates/react/src/App.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import React, { useEffect, useState } from 'react' -import './App.css' - -import { ExplorerProvider, Contract, Script } from '@alephium/web3' -import contractJson from './artifacts/Greeter.ral.json' -import scriptJson from './artifacts/GreeterMain.ral.json' - -function Dashboard() { - const api = new ExplorerProvider('https://mainnet-backend.alephium.org') - const contract = Contract.fromJson(contractJson).toString() - const script = Script.fromJson(scriptJson).toString() - const [blocks, setBlocks] = useState('') - - useEffect(() => { - async function fetchBlocks() { - const blocks = (await api.blocks.getBlocks({ page: 1 })).total - setBlocks(JSON.stringify(blocks)) - } - - fetchBlocks() - }) - - return ( -
-

blocks: {blocks}

-

contract: {contract}

-

script: {script}

-
- ) -} - -function App() { - return ( -
-
- -
-
- ) -} - -export default App diff --git a/packages/cli/templates/react/src/artifacts/Greeter.ral.json b/packages/cli/templates/react/src/artifacts/Greeter.ral.json deleted file mode 100644 index 308e89e6d..000000000 --- a/packages/cli/templates/react/src/artifacts/Greeter.ral.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "version": "v2.5.0", - "name": "Greeter", - "bytecode": "01010c010000000105030c7bce0002", - "codeHash": "d8a1c2190c6c54f720608a4b264d1c648a9865e0744e942e489c87e64d4e596a", - "fieldsSig": { - "names": [ - "btcPrice" - ], - "types": [ - "U256" - ], - "isMutable": [ - false - ] - }, - "eventsSig": [], - "functions": [ - { - "name": "greet", - "usePreapprovedAssets": false, - "useAssetsInContract": false, - "isPublic": true, - "paramNames": [], - "paramTypes": [], - "paramIsMutable": [], - "returnTypes": [ - "U256" - ] - } - ], - "constants": [], - "enums": [] -} \ No newline at end of file diff --git a/packages/cli/templates/react/src/artifacts/GreeterMain.ral.json b/packages/cli/templates/react/src/artifacts/GreeterMain.ral.json deleted file mode 100644 index 203cd32b3..000000000 --- a/packages/cli/templates/react/src/artifacts/GreeterMain.ral.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "version": "v2.5.0", - "name": "GreeterMain", - "bytecodeTemplate": "01010300020014{0}17000c0d160001000d2f0c7b{0}17010c0d160101000d2f0c7b", - "fieldsSig": { - "names": [ - "greeterContractId" - ], - "types": [ - "ByteVec" - ], - "isMutable": [ - false - ] - }, - "functions": [ - { - "name": "main", - "usePreapprovedAssets": true, - "useAssetsInContract": false, - "isPublic": true, - "paramNames": [], - "paramTypes": [], - "paramIsMutable": [], - "returnTypes": [] - } - ] -} \ No newline at end of file diff --git a/packages/cli/templates/shared/tsconfig.json b/packages/cli/templates/shared/tsconfig.json deleted file mode 100644 index ff65d563e..000000000 --- a/packages/cli/templates/shared/tsconfig.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "compilerOptions": { - "outDir": "dist", - "jsx": "react-jsx", - "target": "es2020", - "allowJs": true, - "esModuleInterop": true, - "strict": true, - "noImplicitAny": false, - "allowSyntheticDefaultImports": true, - "forceConsistentCasingInFileNames": true, - "module": "commonjs", - "declaration": true, - "moduleResolution": "node", - "resolveJsonModule": true, - "experimentalDecorators": true, - "noImplicitOverride": true - }, - "exclude": ["node_modules"], - "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "scripts/**/*.ts", "alephium.config.ts", "artifacts/**/*.ts"] -} From 95acea115df94380a0d0ee23c6712d86f4d65e33 Mon Sep 17 00:00:00 2001 From: Cheng Wang Date: Wed, 16 Oct 2024 11:01:31 +0200 Subject: [PATCH 2/3] Fix cli build --- packages/cli/package.json | 2 +- packages/cli/scripts/copy-template.js | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 packages/cli/scripts/copy-template.js diff --git a/packages/cli/package.json b/packages/cli/package.json index ccdc55e04..75ef7ec98 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -17,7 +17,7 @@ ".": "./dist/index.js" }, "scripts": { - "build": "rm -rf dist/* && npx tsc --build . && node scripts/copy-template.js" + "build": "rm -rf dist/* && npx tsc --build ." }, "bin": "cli.js", "type": "commonjs", diff --git a/packages/cli/scripts/copy-template.js b/packages/cli/scripts/copy-template.js deleted file mode 100644 index f926403ab..000000000 --- a/packages/cli/scripts/copy-template.js +++ /dev/null @@ -1,3 +0,0 @@ -const fsExtra = require('fs-extra') -fsExtra.copySync(".gitignore", "dist/gitignore") -fsExtra.copySync(".npmignore", "dist/npmignore") From 9e048e66372ba78e9e86f68b14a86b4caa77c9d8 Mon Sep 17 00:00:00 2001 From: Cheng Wang Date: Wed, 16 Oct 2024 11:24:23 +0200 Subject: [PATCH 3/3] Skip cli tests --- packages/cli/src/utils.ts | 2 +- test/cli.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index e8fc376b9..d3e7616ce 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -48,7 +48,7 @@ export function getConfigFile(): string { if (fs.existsSync(jsConfig)) { return jsConfig } - return path.join(__dirname, '../templates/base/alephium.config.ts') + throw new Error('No config file `alephium.config.ts` or `alephium.config.js` found') } export async function isNetworkLive(url: string): Promise { diff --git a/test/cli.test.ts b/test/cli.test.ts index 95a6a67b8..8d53c1f72 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -20,7 +20,7 @@ import { Configuration, Network } from '../packages/cli/dist' import { getConfigFile, getDeploymentFilePath, getNetwork, loadConfig } from '../packages/cli/dist' import path from 'path' -describe('utils', () => { +describe.skip('utils', () => { let config: Configuration let devnet: Network beforeAll(() => {