Skip to content

Commit 0bbf32a

Browse files
authored
Updated Version (#131)
1 parent f4c3c9d commit 0bbf32a

File tree

7 files changed

+186
-168
lines changed

7 files changed

+186
-168
lines changed

.github/workflows/dart.yml

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,60 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- name: Clone the repository
15-
uses: actions/checkout@v1
14+
- name: Clone the Repository
15+
uses: actions/checkout@v4
1616

1717
- name: Install Tools
18-
run: sudo apt update && sudo apt install lcov
19-
20-
- name: Clone the Flutter repository
21-
uses: actions/checkout@v1
22-
with:
23-
repository: flutter/flutter
24-
ref: 3.3.0
25-
path: flutter
26-
27-
- name: Add the flutter tool to the path
28-
run: |
29-
ls -al "$GITHUB_WORKSPACE/../flutter/bin"
30-
echo "$GITHUB_WORKSPACE/../flutter/bin" >> $GITHUB_PATH
31-
echo "$GITHUB_WORKSPACE/../flutter/bin/cache/dart-sdk/bin" >> $GITHUB_PATH
32-
33-
- name: Populate the Flutter tool's cache of binary artifacts
34-
run: |
35-
flutter config --no-analytics
36-
flutter precache
18+
run: sudo apt update && sudo apt install lcov -y
3719

38-
- name: Reconfigure git to use HTTP authentication
20+
- name: Reconfigure git to Use HTTP Authentication
3921
run: >
4022
git config --global url."https://github.com/".insteadOf '[email protected]:'
4123
42-
- name: Get Flutter packages
24+
- name: Setup Flutter SDK
25+
uses: flutter-actions/setup-flutter@v3
26+
with:
27+
channel: stable
28+
version: 3.19.6
29+
30+
- name: Enable Flutter Desktop
31+
run: flutter config --enable-linux-desktop
32+
shell: bash
33+
34+
- name: Get Flutter Packages
4335
run: flutter pub get
44-
36+
37+
- name: Flutter Create
38+
run: flutter create .
39+
4540
- name: Clone Mozilla's CA cert bundle module into root directory
4641
run: git clone https://github.com/Chia-Network/mozilla-ca.git
4742

48-
- name: Run simulator tests
49-
run: bash ./integration_test/run_tests.sh
43+
- name: Configure Linux Build
44+
run: |
45+
sudo apt install libgtk-3-dev libgtk-3-0 libblkid1 liblzma5 ninja-build libmpv-dev mpv -y
46+
sudo mkdir -p /usr/local/chia_crypto_utils && sudo chmod 777 /usr/local/chia_crypto_utils
47+
48+
- name: Check Flutter Readiness
49+
run: flutter doctor
50+
51+
- name: Run Integration Tests
52+
run: |
53+
export DISPLAY=:99
54+
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
55+
sudo apt install network-manager
56+
./integration_test/run_tests.sh
57+
shell: bash
5058

51-
- name: Run unit tests
59+
- name: Run Unit Tests
5260
run: flutter test test --coverage --coverage-path=coverage/test.info
5361

54-
- name: Merge coverage files
62+
- name: Merge Coverage Files
5563
run: |
5664
lcov --add-tracefile coverage/test.info --add-tracefile coverage/integration_test.info --output-file coverage/merged_coverage.info
5765
rm -rf coverage/*test.info
5866
59-
- name: Generate coverage report
67+
- name: Generate Coverage Report
6068
run: genhtml coverage/merged_coverage.info -o coverage
6169

6270
- name: Upload code coverage to GitHub

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "chia-crypto-utils",
8+
"name": "chia_crypto_utils",
99
"request": "launch",
1010
"type": "dart"
1111
},

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.0.21
4+
5+
- Updated to latest version of Dart
6+
37
## 1.0.20
48

59
- Fixes for pub.dev

integration_test/nft/nft_generation_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void main() async {
107107

108108
expect(nathanNfts.single.metadata, inputMetadata);
109109
});
110-
test('should melt a cat and use result to mint an nft', () async {
110+
test('should melt a cat and use result to mint an nft', () async {
111111
final user = ChiaEnthusiast(fullNodeSimulator, walletSize: 5);
112112
final nftFaucet = ChiaEnthusiast(fullNodeSimulator, walletSize: 5);
113113

Lines changed: 124 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,129 @@
1-
import 'package:chia_crypto_utils/chia_crypto_utils.dart';
2-
3-
void main() {
4-
final coreSecret = KeychainCoreSecret.fromMnemonic(
5-
'goat club mountain ritual rack same bar put fall anxiety minor theme enter card dog lawsuit rather pigeon manual tribe shield decline gentle install'
6-
.split(' '),
7-
);
8-
final keychain = WalletKeychain.fromCoreSecret(coreSecret);
9-
10-
final inputMetadata = NftMetadata(
11-
dataUris: const [
12-
'https://www.chia.net/img/branding/chia-logo.svg',
13-
],
14-
dataHash: Program.fromInt(0).hash(),
15-
);
16-
17-
final did = Program.fromInt(3).hash();
18-
19-
final senderWalletVector = keychain.unhardenedWalletVectors.first;
20-
final receiverWalletVector = keychain.unhardenedWalletVectors.last;
21-
22-
final launcherCoin = CoinPrototype(
23-
parentCoinInfo: Program.fromInt(0).hash(),
24-
puzzlehash: Program.fromInt(1).hash(),
25-
amount: 1,
26-
);
27-
28-
final senderP2Puzzle = getPuzzleFromPk(senderWalletVector.childPublicKey);
29-
30-
final ownershipLayer = NftWalletService.createOwnershipLayerPuzzle(
31-
launcherId: launcherCoin.id,
32-
did: did,
33-
p2Puzzle: senderP2Puzzle,
34-
royaltyPercentage: 200,
35-
);
36-
37-
final fullPuzzle = NftWalletService.createFullPuzzle(
38-
singletonId: launcherCoin.id,
39-
metadata: inputMetadata,
40-
metadataUpdaterPuzzlehash: nftMetadataUpdaterDefault.hash(),
41-
innerPuzzle: ownershipLayer,
42-
);
43-
44-
final uncurriedNft = UncurriedNftPuzzle.fromProgramSync(fullPuzzle);
45-
46-
// solution
47-
48-
final standardInnerSolution = BaseWalletService.makeSolutionFromConditions([
49-
CreateCoinCondition(
50-
receiverWalletVector.puzzlehash,
51-
1,
52-
memos: [senderWalletVector.puzzlehash],
53-
),
54-
]);
55-
56-
final magicCondition = NftDidMagicConditionCondition();
57-
58-
final innerSolution = Program.list([
59-
Program.list([
60-
Program.list([]),
61-
Program.cons(
62-
Program.fromInt(1),
63-
Program.cons(
64-
magicCondition.toProgram(),
65-
standardInnerSolution.rest().first().rest(),
66-
),
67-
),
68-
Program.list([]),
69-
]),
70-
]);
71-
72-
final nftLayerSolution = Program.list([innerSolution]);
73-
final singletonSolution = Program.list([
74-
LineageProof(
75-
parentCoinInfo: launcherCoin.id,
76-
innerPuzzlehash: uncurriedNft!.stateLayer.hash(),
77-
amount: 1,
78-
).toProgram(),
79-
Program.fromInt(1),
80-
nftLayerSolution,
81-
]);
82-
83-
print(fullPuzzle.run(singletonSolution).program);
84-
85-
final innerResult = uncurriedNft.getInnerResult(singletonSolution);
86-
87-
// get new p2 puzzle hash from resulting conditions
88-
final createCoinConditions = BaseWalletService.extractConditionsFromResult(
89-
innerResult,
90-
CreateCoinCondition.isThisCondition,
91-
CreateCoinCondition.fromProgram,
92-
);
93-
94-
final nftOutputConditions = createCoinConditions.where(
95-
(element) =>
96-
element.amount == 1 &&
97-
element.memos != null &&
98-
element.memos!.isNotEmpty,
99-
);
100-
101-
if (nftOutputConditions.isEmpty) {
102-
throw Exception('No nft output condtions to find inner puzzle hash with');
103-
}
1+
@Skip('Not tested yet')
1042

105-
if (nftOutputConditions.length > 1) {
106-
throw Exception('more than one nft output condition');
107-
}
108-
109-
// get new did from resulting conditions
110-
final didMagicConditions = BaseWalletService.extractConditionsFromResult(
111-
innerResult,
112-
NftDidMagicConditionCondition.isThisCondition,
113-
NftDidMagicConditionCondition.fromProgram,
114-
);
3+
import 'package:chia_crypto_utils/chia_crypto_utils.dart';
4+
import 'package:test/test.dart';
1155

116-
if (didMagicConditions.length > 1) {
117-
throw Exception('more than one nft didMagicConditions condition');
6+
void main() async {
7+
if (!(await SimulatorUtils.checkIfSimulatorIsRunning())) {
8+
print(SimulatorUtils.simulatorNotRunningWarning);
9+
return;
11810
}
11911

120-
// final innerPuzzleReveal = NftWalletService.constructOwnershipLayer(
121-
// currentOwnerDid: null,
122-
// transferProgram: uncurriedNft.ownershipLayerInfo!.transferProgram,
123-
// innerPuzzle: ownershipInfo.ownershipLayerP2Puzzle,
124-
// );
12+
test('basic nft test', () async {
13+
final coreSecret = KeychainCoreSecret.fromMnemonic(
14+
'goat club mountain ritual rack same bar put fall anxiety minor theme enter card dog lawsuit rather pigeon manual tribe shield decline gentle install'
15+
.split(' '),
16+
);
17+
final keychain = WalletKeychain.fromCoreSecret(coreSecret);
18+
19+
final inputMetadata = NftMetadata(
20+
dataUris: const [
21+
'https://www.chia.net/wp-content/uploads/2023/01/chia-logo-dark.svg',
22+
],
23+
dataHash: Program.fromInt(0).hash(),
24+
);
25+
26+
final did = Program.fromInt(3).hash();
27+
28+
final senderWalletVector = keychain.unhardenedWalletVectors.first;
29+
final receiverWalletVector = keychain.unhardenedWalletVectors.last;
30+
31+
final launcherCoin = CoinPrototype(
32+
parentCoinInfo: Program.fromInt(0).hash(),
33+
puzzlehash: Program.fromInt(1).hash(),
34+
amount: 1,
35+
);
36+
37+
final senderP2Puzzle = getPuzzleFromPk(senderWalletVector.childPublicKey);
38+
39+
final ownershipLayer = NftWalletService.createOwnershipLayerPuzzle(
40+
launcherId: launcherCoin.id,
41+
did: did,
42+
p2Puzzle: senderP2Puzzle,
43+
royaltyPercentage: 200,
44+
);
45+
46+
final fullPuzzle = NftWalletService.createFullPuzzle(
47+
singletonId: launcherCoin.id,
48+
metadata: inputMetadata,
49+
metadataUpdaterPuzzlehash: nftMetadataUpdaterDefault.hash(),
50+
innerPuzzle: ownershipLayer,
51+
);
52+
53+
final uncurriedNft = UncurriedNftPuzzle.fromProgramSync(fullPuzzle);
54+
55+
// solution
56+
57+
final standardInnerSolution = BaseWalletService.makeSolutionFromConditions([
58+
CreateCoinCondition(
59+
receiverWalletVector.puzzlehash,
60+
1,
61+
memos: [senderWalletVector.puzzlehash],
62+
),
63+
]);
64+
65+
final magicCondition = NftDidMagicConditionCondition();
66+
67+
final innerSolution = Program.list([
68+
Program.list([
69+
Program.list([]),
70+
Program.cons(
71+
Program.fromInt(1),
72+
Program.cons(
73+
magicCondition.toProgram(),
74+
standardInnerSolution.rest().first().rest(),
75+
),
76+
),
77+
Program.list([]),
78+
]),
79+
]);
80+
81+
final nftLayerSolution = Program.list([innerSolution]);
82+
final singletonSolution = Program.list([
83+
LineageProof(
84+
parentCoinInfo: launcherCoin.id,
85+
innerPuzzlehash: uncurriedNft!.stateLayer.hash(),
86+
amount: 1,
87+
).toProgram(),
88+
Program.fromInt(1),
89+
nftLayerSolution,
90+
]);
91+
92+
print(fullPuzzle.run(singletonSolution).program);
93+
94+
final innerResult = uncurriedNft.getInnerResult(singletonSolution);
95+
96+
// get new p2 puzzle hash from resulting conditions
97+
final createCoinConditions = BaseWalletService.extractConditionsFromResult(
98+
innerResult,
99+
CreateCoinCondition.isThisCondition,
100+
CreateCoinCondition.fromProgram,
101+
);
102+
103+
final nftOutputConditions = createCoinConditions.where(
104+
(element) =>
105+
element.amount == 1 &&
106+
element.memos != null &&
107+
element.memos!.isNotEmpty,
108+
);
109+
110+
if (nftOutputConditions.isEmpty) {
111+
throw Exception('No nft output condtions to find inner puzzle hash with');
112+
}
113+
114+
if (nftOutputConditions.length > 1) {
115+
throw Exception('more than one nft output condition');
116+
}
117+
118+
// get new did from resulting conditions
119+
final didMagicConditions = BaseWalletService.extractConditionsFromResult(
120+
innerResult,
121+
NftDidMagicConditionCondition.isThisCondition,
122+
NftDidMagicConditionCondition.fromProgram,
123+
);
124+
125+
if (didMagicConditions.length > 1) {
126+
throw Exception('more than one nft didMagicConditions condition');
127+
}
128+
});
125129
}

integration_test/run_tests.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ function test_subdirectories() {
3232

3333
echo "running tests in $name"
3434

35-
flutter test ./$dir --concurrency=1 --coverage --coverage-path=coverage/${name}_lcov.info
35+
for file in "$dir"/*_test.dart; do
36+
echo "running tests in $file"
37+
38+
flutter test -d linux $file --coverage --coverage-path=coverage/${name}_lcov.info
39+
done
3640

3741
stop_simulator
3842
else
@@ -46,4 +50,4 @@ test_subdirectories
4650

4751
# merge coverage files
4852
printf -- '-add-tracefile\0%s\0' coverage/*.info | xargs -0 lcov --output-file coverage/integration_test.info
49-
rm -rf coverage/*lcov.info
53+
rm -rf coverage/*lcov.info

0 commit comments

Comments
 (0)