|
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') |
104 | 2 |
|
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'; |
115 | 5 |
|
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; |
118 | 10 | } |
119 | 11 |
|
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 | + }); |
125 | 129 | } |
0 commit comments