Skip to content

Commit

Permalink
Updated Version (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkverbito authored Jun 6, 2024
1 parent f4c3c9d commit 0bbf32a
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 168 deletions.
66 changes: 37 additions & 29 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 '[email protected]:'
- 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
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "chia-crypto-utils",
"name": "chia_crypto_utils",
"request": "launch",
"type": "dart"
},
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.21

- Updated to latest version of Dart

## 1.0.20

- Fixes for pub.dev
Expand Down
2 changes: 1 addition & 1 deletion integration_test/nft/nft_generation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
244 changes: 124 additions & 120 deletions integration_test/nft/nft_puzzles_test.dart
Original file line number Diff line number Diff line change
@@ -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');
}
});
}
8 changes: 6 additions & 2 deletions integration_test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
rm -rf coverage/*lcov.info
Loading

0 comments on commit 0bbf32a

Please sign in to comment.