From 0bbf32a422e2b624cd3f84b7b643b0f83f18be51 Mon Sep 17 00:00:00 2001 From: darkverbito Date: Thu, 6 Jun 2024 14:26:10 -0500 Subject: [PATCH] Updated Version (#131) --- .github/workflows/dart.yml | 66 ++--- .vscode/launch.json | 2 +- CHANGELOG.md | 4 + integration_test/nft/nft_generation_test.dart | 2 +- integration_test/nft/nft_puzzles_test.dart | 244 +++++++++--------- integration_test/run_tests.sh | 8 +- pubspec.yaml | 28 +- 7 files changed, 186 insertions(+), 168 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 512a852d..60a0af6d 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -11,52 +11,60 @@ jobs: runs-on: ubuntu-latest steps: - - name: Clone the repository - uses: actions/checkout@v1 + - name: Clone the Repository + uses: actions/checkout@v4 - name: Install Tools - run: sudo apt update && sudo apt install lcov - - - name: Clone the Flutter repository - uses: actions/checkout@v1 - with: - repository: flutter/flutter - ref: 3.3.0 - path: flutter - - - name: Add the flutter tool to the path - run: | - ls -al "$GITHUB_WORKSPACE/../flutter/bin" - echo "$GITHUB_WORKSPACE/../flutter/bin" >> $GITHUB_PATH - echo "$GITHUB_WORKSPACE/../flutter/bin/cache/dart-sdk/bin" >> $GITHUB_PATH - - - name: Populate the Flutter tool's cache of binary artifacts - run: | - flutter config --no-analytics - flutter precache + run: sudo apt update && sudo apt install lcov -y - - name: Reconfigure git to use HTTP authentication + - name: Reconfigure git to Use HTTP Authentication run: > git config --global url."https://github.com/".insteadOf 'git@github.com:' - - name: Get Flutter packages + - name: Setup Flutter SDK + uses: flutter-actions/setup-flutter@v3 + with: + channel: stable + version: 3.19.6 + + - name: Enable Flutter Desktop + run: flutter config --enable-linux-desktop + shell: bash + + - name: Get Flutter Packages run: flutter pub get - + + - name: Flutter Create + run: flutter create . + - name: Clone Mozilla's CA cert bundle module into root directory run: git clone https://github.com/Chia-Network/mozilla-ca.git - - name: Run simulator tests - run: bash ./integration_test/run_tests.sh + - name: Configure Linux Build + run: | + sudo apt install libgtk-3-dev libgtk-3-0 libblkid1 liblzma5 ninja-build libmpv-dev mpv -y + sudo mkdir -p /usr/local/chia_crypto_utils && sudo chmod 777 /usr/local/chia_crypto_utils + + - name: Check Flutter Readiness + run: flutter doctor + + - name: Run Integration Tests + run: | + export DISPLAY=:99 + sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & + sudo apt install network-manager + ./integration_test/run_tests.sh + shell: bash - - name: Run unit tests + - name: Run Unit Tests run: flutter test test --coverage --coverage-path=coverage/test.info - - name: Merge coverage files + - name: Merge Coverage Files run: | lcov --add-tracefile coverage/test.info --add-tracefile coverage/integration_test.info --output-file coverage/merged_coverage.info rm -rf coverage/*test.info - - name: Generate coverage report + - name: Generate Coverage Report run: genhtml coverage/merged_coverage.info -o coverage - name: Upload code coverage to GitHub diff --git a/.vscode/launch.json b/.vscode/launch.json index edf3db78..69451969 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,7 @@ "version": "0.2.0", "configurations": [ { - "name": "chia-crypto-utils", + "name": "chia_crypto_utils", "request": "launch", "type": "dart" }, diff --git a/CHANGELOG.md b/CHANGELOG.md index 71c67160..0ea23023 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.0.21 + +- Updated to latest version of Dart + ## 1.0.20 - Fixes for pub.dev diff --git a/integration_test/nft/nft_generation_test.dart b/integration_test/nft/nft_generation_test.dart index c919742c..3169d537 100644 --- a/integration_test/nft/nft_generation_test.dart +++ b/integration_test/nft/nft_generation_test.dart @@ -107,7 +107,7 @@ void main() async { expect(nathanNfts.single.metadata, inputMetadata); }); - test('should melt a cat and use result to mint an nft', () async { + test('should melt a cat and use result to mint an nft', () async { final user = ChiaEnthusiast(fullNodeSimulator, walletSize: 5); final nftFaucet = ChiaEnthusiast(fullNodeSimulator, walletSize: 5); diff --git a/integration_test/nft/nft_puzzles_test.dart b/integration_test/nft/nft_puzzles_test.dart index 71068ed9..e8c6d0af 100644 --- a/integration_test/nft/nft_puzzles_test.dart +++ b/integration_test/nft/nft_puzzles_test.dart @@ -1,125 +1,129 @@ -import 'package:chia_crypto_utils/chia_crypto_utils.dart'; - -void main() { - final coreSecret = KeychainCoreSecret.fromMnemonic( - 'goat club mountain ritual rack same bar put fall anxiety minor theme enter card dog lawsuit rather pigeon manual tribe shield decline gentle install' - .split(' '), - ); - final keychain = WalletKeychain.fromCoreSecret(coreSecret); - - final inputMetadata = NftMetadata( - dataUris: const [ - 'https://www.chia.net/img/branding/chia-logo.svg', - ], - dataHash: Program.fromInt(0).hash(), - ); - - final did = Program.fromInt(3).hash(); - - final senderWalletVector = keychain.unhardenedWalletVectors.first; - final receiverWalletVector = keychain.unhardenedWalletVectors.last; - - final launcherCoin = CoinPrototype( - parentCoinInfo: Program.fromInt(0).hash(), - puzzlehash: Program.fromInt(1).hash(), - amount: 1, - ); - - final senderP2Puzzle = getPuzzleFromPk(senderWalletVector.childPublicKey); - - final ownershipLayer = NftWalletService.createOwnershipLayerPuzzle( - launcherId: launcherCoin.id, - did: did, - p2Puzzle: senderP2Puzzle, - royaltyPercentage: 200, - ); - - final fullPuzzle = NftWalletService.createFullPuzzle( - singletonId: launcherCoin.id, - metadata: inputMetadata, - metadataUpdaterPuzzlehash: nftMetadataUpdaterDefault.hash(), - innerPuzzle: ownershipLayer, - ); - - final uncurriedNft = UncurriedNftPuzzle.fromProgramSync(fullPuzzle); - - // solution - - final standardInnerSolution = BaseWalletService.makeSolutionFromConditions([ - CreateCoinCondition( - receiverWalletVector.puzzlehash, - 1, - memos: [senderWalletVector.puzzlehash], - ), - ]); - - final magicCondition = NftDidMagicConditionCondition(); - - final innerSolution = Program.list([ - Program.list([ - Program.list([]), - Program.cons( - Program.fromInt(1), - Program.cons( - magicCondition.toProgram(), - standardInnerSolution.rest().first().rest(), - ), - ), - Program.list([]), - ]), - ]); - - final nftLayerSolution = Program.list([innerSolution]); - final singletonSolution = Program.list([ - LineageProof( - parentCoinInfo: launcherCoin.id, - innerPuzzlehash: uncurriedNft!.stateLayer.hash(), - amount: 1, - ).toProgram(), - Program.fromInt(1), - nftLayerSolution, - ]); - - print(fullPuzzle.run(singletonSolution).program); - - final innerResult = uncurriedNft.getInnerResult(singletonSolution); - - // get new p2 puzzle hash from resulting conditions - final createCoinConditions = BaseWalletService.extractConditionsFromResult( - innerResult, - CreateCoinCondition.isThisCondition, - CreateCoinCondition.fromProgram, - ); - - final nftOutputConditions = createCoinConditions.where( - (element) => - element.amount == 1 && - element.memos != null && - element.memos!.isNotEmpty, - ); - - if (nftOutputConditions.isEmpty) { - throw Exception('No nft output condtions to find inner puzzle hash with'); - } +@Skip('Not tested yet') - if (nftOutputConditions.length > 1) { - throw Exception('more than one nft output condition'); - } - - // get new did from resulting conditions - final didMagicConditions = BaseWalletService.extractConditionsFromResult( - innerResult, - NftDidMagicConditionCondition.isThisCondition, - NftDidMagicConditionCondition.fromProgram, - ); +import 'package:chia_crypto_utils/chia_crypto_utils.dart'; +import 'package:test/test.dart'; - if (didMagicConditions.length > 1) { - throw Exception('more than one nft didMagicConditions condition'); +void main() async { + if (!(await SimulatorUtils.checkIfSimulatorIsRunning())) { + print(SimulatorUtils.simulatorNotRunningWarning); + return; } - // final innerPuzzleReveal = NftWalletService.constructOwnershipLayer( - // currentOwnerDid: null, - // transferProgram: uncurriedNft.ownershipLayerInfo!.transferProgram, - // innerPuzzle: ownershipInfo.ownershipLayerP2Puzzle, - // ); + test('basic nft test', () async { + final coreSecret = KeychainCoreSecret.fromMnemonic( + 'goat club mountain ritual rack same bar put fall anxiety minor theme enter card dog lawsuit rather pigeon manual tribe shield decline gentle install' + .split(' '), + ); + final keychain = WalletKeychain.fromCoreSecret(coreSecret); + + final inputMetadata = NftMetadata( + dataUris: const [ + 'https://www.chia.net/wp-content/uploads/2023/01/chia-logo-dark.svg', + ], + dataHash: Program.fromInt(0).hash(), + ); + + final did = Program.fromInt(3).hash(); + + final senderWalletVector = keychain.unhardenedWalletVectors.first; + final receiverWalletVector = keychain.unhardenedWalletVectors.last; + + final launcherCoin = CoinPrototype( + parentCoinInfo: Program.fromInt(0).hash(), + puzzlehash: Program.fromInt(1).hash(), + amount: 1, + ); + + final senderP2Puzzle = getPuzzleFromPk(senderWalletVector.childPublicKey); + + final ownershipLayer = NftWalletService.createOwnershipLayerPuzzle( + launcherId: launcherCoin.id, + did: did, + p2Puzzle: senderP2Puzzle, + royaltyPercentage: 200, + ); + + final fullPuzzle = NftWalletService.createFullPuzzle( + singletonId: launcherCoin.id, + metadata: inputMetadata, + metadataUpdaterPuzzlehash: nftMetadataUpdaterDefault.hash(), + innerPuzzle: ownershipLayer, + ); + + final uncurriedNft = UncurriedNftPuzzle.fromProgramSync(fullPuzzle); + + // solution + + final standardInnerSolution = BaseWalletService.makeSolutionFromConditions([ + CreateCoinCondition( + receiverWalletVector.puzzlehash, + 1, + memos: [senderWalletVector.puzzlehash], + ), + ]); + + final magicCondition = NftDidMagicConditionCondition(); + + final innerSolution = Program.list([ + Program.list([ + Program.list([]), + Program.cons( + Program.fromInt(1), + Program.cons( + magicCondition.toProgram(), + standardInnerSolution.rest().first().rest(), + ), + ), + Program.list([]), + ]), + ]); + + final nftLayerSolution = Program.list([innerSolution]); + final singletonSolution = Program.list([ + LineageProof( + parentCoinInfo: launcherCoin.id, + innerPuzzlehash: uncurriedNft!.stateLayer.hash(), + amount: 1, + ).toProgram(), + Program.fromInt(1), + nftLayerSolution, + ]); + + print(fullPuzzle.run(singletonSolution).program); + + final innerResult = uncurriedNft.getInnerResult(singletonSolution); + + // get new p2 puzzle hash from resulting conditions + final createCoinConditions = BaseWalletService.extractConditionsFromResult( + innerResult, + CreateCoinCondition.isThisCondition, + CreateCoinCondition.fromProgram, + ); + + final nftOutputConditions = createCoinConditions.where( + (element) => + element.amount == 1 && + element.memos != null && + element.memos!.isNotEmpty, + ); + + if (nftOutputConditions.isEmpty) { + throw Exception('No nft output condtions to find inner puzzle hash with'); + } + + if (nftOutputConditions.length > 1) { + throw Exception('more than one nft output condition'); + } + + // get new did from resulting conditions + final didMagicConditions = BaseWalletService.extractConditionsFromResult( + innerResult, + NftDidMagicConditionCondition.isThisCondition, + NftDidMagicConditionCondition.fromProgram, + ); + + if (didMagicConditions.length > 1) { + throw Exception('more than one nft didMagicConditions condition'); + } + }); } diff --git a/integration_test/run_tests.sh b/integration_test/run_tests.sh index cb448a25..96d26447 100755 --- a/integration_test/run_tests.sh +++ b/integration_test/run_tests.sh @@ -32,7 +32,11 @@ function test_subdirectories() { echo "running tests in $name" - flutter test ./$dir --concurrency=1 --coverage --coverage-path=coverage/${name}_lcov.info + for file in "$dir"/*_test.dart; do + echo "running tests in $file" + + flutter test -d linux $file --coverage --coverage-path=coverage/${name}_lcov.info + done stop_simulator else @@ -46,4 +50,4 @@ test_subdirectories # merge coverage files printf -- '-add-tracefile\0%s\0' coverage/*.info | xargs -0 lcov --output-file coverage/integration_test.info -rm -rf coverage/*lcov.info \ No newline at end of file +rm -rf coverage/*lcov.info diff --git a/pubspec.yaml b/pubspec.yaml index 61fdf480..7e264119 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,13 +1,10 @@ name: chia_crypto_utils description: Chia Crypto Utils repository provides an object model for working with Chia primitives serving as a basis for a Chia client. -version: 1.0.20 +version: 1.0.21 repository: https://github.com/irulast/chia-crypto-utils environment: - sdk: '>=2.18.0 <3.0.0' - -scripts: - integration_tests: 'dart test integration_test/ --concurrency=1' + sdk: ">=2.19.0 <4.0.0" dependencies: args: ^2.3.1 @@ -20,29 +17,30 @@ dependencies: collection: ^1.16.0 compute: ^1.0.2 crypto: ^3.0.1 - csv: ^5.0.1 - deep_pick: ^0.10.0 + csv: ^6.0.0 + deep_pick: ^1.0.0 equatable: ^2.0.5 get_it: ^7.2.0 hex: ^0.2.0 - http: ^0.13.4 - injector: ^2.0.0 - intl: ^0.17.0 + http: ^1.2.1 + injector: ^3.0.0 + intl: ^0.19.0 meta: ^1.7.0 path: ^1.8.1 quiver: ^3.0.1+1 synchronized: ^3.0.1 tuple: ^2.0.2 - uuid: ^3.0.6 - walletconnect_dart_v2_i: ^2.1.8 + uuid: ^4.4.0 + walletconnect_dart_v2_i: ^2.1.9 yaml: ^3.1.1 dev_dependencies: - lints: ^2.0.1 - rps: ^0.6.3 + lints: ^4.0.0 test: ^1.19.3 test_process: ^2.1.0 - very_good_analysis: ^3.1.0 + very_good_analysis: ^5.1.0 + integration_test: + sdk: flutter false_secrets: - /lib/src/networks/chia/mainnet/ssl/private_full_node.key