pshenmic-dpp 2.0.0-dev.2 → 2.0.0-dev.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/binaries/bindingsTypes.d.ts +200 -37
- package/dist/binaries/bindingsTypes.js +4 -3
- package/dist/binaries/native/aarch64-apple-darwin/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/x86_64-apple-darwin/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/x86_64-unknown-linux-gnu/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/x86_64-unknown-linux-musl/pshenmic_dpp.node +0 -0
- package/dist/binaries/node.cjs +50 -0
- package/dist/binaries/node.d.cts +2 -0
- package/dist/binaries/pshenmic_dpp.android.node/arm64-v8a/libpshenmic_dpp.so +0 -0
- package/dist/binaries/pshenmic_dpp.apple.node/Info.plist +29 -0
- package/dist/binaries/pshenmic_dpp.apple.node/ios-arm64-simulator/libpshenmic_dpp.framework/Info.plist +24 -0
- package/dist/binaries/pshenmic_dpp.apple.node/ios-arm64-simulator/libpshenmic_dpp.framework/libpshenmic_dpp +0 -0
- package/dist/binaries/pshenmic_dpp.apple.node/react-native-node-api-module +0 -0
- package/dist/binaries/pshenmic_dpp.d.ts +15 -1
- package/dist/binaries/pshenmic_dpp.js +1 -1
- package/dist/binaries/wasm/wasmBytes.cjs +3 -0
- package/dist/binaries/wasm/wasmBytes.d.cts +1 -0
- package/dist/binaries/wasm.d.ts +15 -1
- package/dist/binaries/wasm.js +2 -44
- package/dist/binaries/wasmCreation.cjs +46 -0
- package/dist/binaries/wasmCreation.d.cts +2 -0
- package/dist/src/dpp/dpp.d.ts +11 -2
- package/dist/src/dpp/dpp.js +11 -2
- package/dist/src/dpp/structs/AddressTransitions/AddressCreditWithdrawalTransition.d.ts +1 -1
- package/dist/src/dpp/structs/AddressTransitions/AddressCreditWithdrawalTransition.js +2 -2
- package/dist/src/dpp/structs/AddressTransitions/AddressFundingFromAssetLockTransition.d.ts +1 -1
- package/dist/src/dpp/structs/AddressTransitions/AddressFundingFromAssetLockTransition.js +3 -3
- package/dist/src/dpp/structs/AddressTransitions/AddressFundsTransferTransition.d.ts +1 -1
- package/dist/src/dpp/structs/AddressTransitions/AddressFundsTransferTransition.js +3 -3
- package/dist/src/dpp/structs/AddressTransitions/IdentityCreateFromAddressesTransition.d.ts +1 -1
- package/dist/src/dpp/structs/AddressTransitions/IdentityCreateFromAddressesTransition.js +2 -2
- package/dist/src/dpp/structs/AddressTransitions/IdentityCreditTransferToAddressesTransition.js +1 -1
- package/dist/src/dpp/structs/AddressTransitions/IdentityTopUpFromAddressesTransition.d.ts +1 -1
- package/dist/src/dpp/structs/AddressTransitions/IdentityTopUpFromAddressesTransition.js +2 -2
- package/dist/src/dpp/structs/AddressTransitions/entities/InputAddress.d.ts +4 -3
- package/dist/src/dpp/structs/AddressTransitions/entities/InputAddress.js +5 -4
- package/dist/src/dpp/structs/AddressTransitions/entities/OutputAddress.d.ts +4 -3
- package/dist/src/dpp/structs/AddressTransitions/entities/OutputAddress.js +5 -4
- package/dist/src/dpp/structs/AddressTransitions/entities/OutputAddressNullableCredits.d.ts +4 -3
- package/dist/src/dpp/structs/AddressTransitions/entities/OutputAddressNullableCredits.js +5 -4
- package/dist/src/dpp/structs/AssetLockProof/AssetLockProof.js +1 -1
- package/dist/src/dpp/structs/AssetLockProof/ChainAssetLockProof.js +2 -2
- package/dist/src/dpp/structs/AssetLockProof/InstantAssetLockProof.js +1 -1
- package/dist/src/dpp/structs/AssetLockProof/OutPoint.js +1 -1
- package/dist/src/dpp/structs/AssetLockProof/Transaction.js +1 -1
- package/dist/src/dpp/structs/AssetLockProof/TxIn.js +1 -1
- package/dist/src/dpp/structs/AssetLockProof/TxOut.js +1 -1
- package/dist/src/dpp/structs/AssetLockProof/Witness.js +1 -1
- package/dist/src/dpp/structs/Batch/BatchTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/BatchedTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/DocumentBaseTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/DocumentTransition.d.ts +1 -0
- package/dist/src/dpp/structs/Batch/DocumentTransition.js +4 -1
- package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentCreateTransition.d.ts +1 -1
- package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentCreateTransition.js +2 -2
- package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentDeleteTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentPurchaseTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentReplaceTransition.d.ts +1 -1
- package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentReplaceTransition.js +2 -2
- package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentTransferTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/DocumentTransitions/DocumentUpdatePriceTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/PrefundedVotingBalance.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenBaseTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenPaymentInfo.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenPricingSchedule.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenTransition.d.ts +1 -0
- package/dist/src/dpp/structs/Batch/TokenTransition.js +4 -1
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenBurnTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenClaimTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenConfigUpdateTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenDestroyFrozenFundsTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenDirectPurchaseTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenEmergencyActionTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenFreezeTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenMintTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenSetPriceForDirectPurchaseTransition.js +1 -1
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenTransferTransition.d.ts +3 -0
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenTransferTransition.js +8 -1
- package/dist/src/dpp/structs/Batch/TokenTransitions/TokenUnFreezeTransition.js +1 -1
- package/dist/src/dpp/structs/ContractBounds.js +1 -1
- package/dist/src/dpp/structs/CoreScript.js +1 -1
- package/dist/src/dpp/structs/DataContract.d.ts +6 -4
- package/dist/src/dpp/structs/DataContract.js +8 -2
- package/dist/src/dpp/structs/DataContractTransitions/DataContractCreateTransition.js +1 -1
- package/dist/src/dpp/structs/DataContractTransitions/DataContractUpdateTransition.js +1 -1
- package/dist/src/dpp/structs/Document.d.ts +1 -1
- package/dist/src/dpp/structs/Document.js +1 -1
- package/dist/src/dpp/structs/EncryptedNote/PrivateEncryptedNote.js +1 -1
- package/dist/src/dpp/structs/EncryptedNote/SharedEncryptedNote.js +1 -1
- package/dist/src/dpp/structs/GroupStateTransitionInfo.js +1 -1
- package/dist/src/dpp/structs/Identifier.js +1 -1
- package/dist/src/dpp/structs/Identity.js +1 -1
- package/dist/src/dpp/structs/IdentityPublicKey.d.ts +1 -0
- package/dist/src/dpp/structs/IdentityPublicKey.js +6 -1
- package/dist/src/dpp/structs/IdentityPublicKeyInCreation.d.ts +1 -0
- package/dist/src/dpp/structs/IdentityPublicKeyInCreation.js +6 -1
- package/dist/src/dpp/structs/IdentityTransitions/IdentityCreateTransition.js +1 -1
- package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditTransfer.js +1 -1
- package/dist/src/dpp/structs/IdentityTransitions/IdentityCreditWithdrawalTransition.js +1 -1
- package/dist/src/dpp/structs/IdentityTransitions/IdentityTopUpTransition.js +1 -1
- package/dist/src/dpp/structs/IdentityTransitions/IdentityUpdateTransition.js +1 -1
- package/dist/src/dpp/structs/InstantLock.js +1 -1
- package/dist/src/dpp/structs/MasternodeVote/MasternodeVoteTransition.d.ts +0 -2
- package/dist/src/dpp/structs/MasternodeVote/MasternodeVoteTransition.js +1 -7
- package/dist/src/dpp/structs/MasternodeVote/Vote.js +1 -1
- package/dist/src/dpp/structs/MasternodeVote/VotePoll.d.ts +1 -1
- package/dist/src/dpp/structs/MasternodeVote/VotePoll.js +3 -3
- package/dist/src/dpp/structs/PartialIdentity.js +1 -1
- package/dist/src/dpp/structs/{Address → PlatformAddress}/AddressWitness.d.ts +2 -2
- package/dist/src/dpp/structs/{Address → PlatformAddress}/AddressWitness.js +2 -2
- package/dist/src/dpp/structs/{Address → PlatformAddress}/PlatformAddress.d.ts +4 -2
- package/dist/src/dpp/structs/{Address → PlatformAddress}/PlatformAddress.js +9 -3
- package/dist/src/dpp/structs/PrivateKey.js +1 -1
- package/dist/src/dpp/structs/PublicKey.js +1 -1
- package/dist/src/dpp/structs/ShieldedTransitions/IdentityCreateFromShieldedPoolTransition.d.ts +31 -0
- package/dist/src/dpp/structs/ShieldedTransitions/IdentityCreateFromShieldedPoolTransition.js +73 -0
- package/dist/src/dpp/structs/ShieldedTransitions/SerializedAction.d.ts +19 -0
- package/dist/src/dpp/structs/ShieldedTransitions/SerializedAction.js +49 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldFromAssetLockTransition.d.ts +30 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldFromAssetLockTransition.js +77 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldTransition.d.ts +32 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldTransition.js +78 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedTransferTransition.d.ts +21 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedTransferTransition.js +51 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedWithdrawalTransition.d.ts +29 -0
- package/dist/src/dpp/structs/ShieldedTransitions/ShieldedWithdrawalTransition.js +71 -0
- package/dist/src/dpp/structs/ShieldedTransitions/UnshieldTransition.d.ts +25 -0
- package/dist/src/dpp/structs/ShieldedTransitions/UnshieldTransition.js +59 -0
- package/dist/src/dpp/structs/StateTransition.d.ts +1 -0
- package/dist/src/dpp/structs/StateTransition.js +3 -0
- package/dist/src/dpp/structs/TokenConfiguration/ActionTaker.js +1 -1
- package/dist/src/dpp/structs/TokenConfiguration/ChangeControlRules.js +1 -1
- package/dist/src/dpp/structs/TokenConfiguration/Group.js +1 -1
- package/dist/src/dpp/structs/TokenConfiguration/TokenConfiguration.js +1 -1
- package/dist/src/dpp/structs/TokenConfiguration/TokenConfigurationConvention.js +1 -1
- package/dist/src/dpp/structs/TokenConfiguration/TokenConfigurationLocalization.js +1 -1
- package/dist/src/dpp/structs/TokenConfiguration/TokenDistributionRules.js +1 -1
- package/dist/src/dpp/structs/TokenConfiguration/TokenKeepsHistoryRules.js +1 -1
- package/dist/src/dpp/structs/TokenConfiguration/TokenMarketplaceRules.js +1 -1
- package/dist/src/dpp/structs/TokenConfiguration/TokenPerpetualDistribution.js +1 -1
- package/dist/src/dpp/structs/TokenConfiguration/TokenPreProgrammedDistribution.js +1 -1
- package/dist/src/dpp/types.d.ts +50 -11
- package/dist/src/dpp/utils.d.ts +4 -3
- package/dist/src/dpp/utils.js +24 -6
- package/dist/src/dpp/verify/Contested/verifyVotePollVoteStateProof.d.ts +1 -1
- package/dist/src/dpp/verify/Contested/verifyVotePollVoteStateProof.js +1 -1
- package/dist/src/dpp/verify/PlatformAddress/verifyPlatformAddressInfo.d.ts +2 -0
- package/dist/src/dpp/verify/PlatformAddress/verifyPlatformAddressInfo.js +12 -0
- package/dist/src/dpp/verify/PlatformAddress/verifyPlatformAddressesInfos.d.ts +2 -0
- package/dist/src/dpp/verify/PlatformAddress/verifyPlatformAddressesInfos.js +14 -0
- package/dist/src/dpp/verify/StateTransition/utils.js +80 -15
- package/dist/src/dpp/verify/System/verifyEpochsInfoProof.js +1 -1
- package/dist/src/dpp/verify/Tokens/verifyTokenBalancesForIdentitiesProof.js +1 -1
- package/dist/src/dpp/verify/Tokens/verifyTokensBalancesForIdentityProof.js +1 -1
- package/dist/src/native.d.ts +3 -0
- package/dist/src/native.js +8 -0
- package/dist/utils/{base122.js → base122.cjs} +3 -1
- package/package.json +18 -28
- package/tests/unit/DataContract.spec.ts +281 -0
- package/tests/unit/DynamicValue.spec.ts +42 -2
- package/tests/unit/Identifier.spec.ts +1 -1
- package/tests/unit/Identity.spec.ts +1 -1
- package/tests/unit/IdentityPublicKey.spec.ts +1 -1
- package/tests/unit/NodeApi.spec.ts +49 -0
- package/tests/unit/ShieldedTransitions.spec.ts +709 -0
- package/tests/unit/TokenConfiguration.spec.ts +114 -0
- package/tests/unit/WebAssembly.spec.ts +49 -0
- package/tests/unit/utils/buildTokenConfiguration.ts +66 -0
- package/dist/binaries/pshenmic_dpp.android.node/x86_64/libpshenmic_dpp.so +0 -0
- package/dist/binaries/wasm/wasmBytes.d.ts +0 -2
- package/dist/binaries/wasm/wasmBytes.js +0 -2
- /package/dist/utils/{base122.d.ts → base122.d.cts} +0 -0
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SerializedActionWASM,
|
|
3
|
+
ShieldedTransferTransitionWASM,
|
|
4
|
+
ShieldTransitionWASM,
|
|
5
|
+
UnshieldTransitionWASM,
|
|
6
|
+
ShieldFromAssetLockTransitionWASM,
|
|
7
|
+
ShieldedWithdrawalTransitionWASM,
|
|
8
|
+
IdentityCreateFromShieldedPoolTransitionWASM,
|
|
9
|
+
InputAddressWASM,
|
|
10
|
+
AddressFundsFeeStrategyStepWASM,
|
|
11
|
+
AddressWitnessWASM,
|
|
12
|
+
PlatformAddressWASM,
|
|
13
|
+
AssetLockProofWASM,
|
|
14
|
+
OutPointWASM,
|
|
15
|
+
CoreScriptWASM,
|
|
16
|
+
IdentityPublicKeyInCreationWASM,
|
|
17
|
+
IdentifierWASM,
|
|
18
|
+
Purpose,
|
|
19
|
+
SecurityLevel,
|
|
20
|
+
KeyType,
|
|
21
|
+
StateTransitionWASM
|
|
22
|
+
} from 'pshenmic-dpp'
|
|
23
|
+
|
|
24
|
+
function randomBytes (length: number): Uint8Array {
|
|
25
|
+
const bytes = new Uint8Array(length)
|
|
26
|
+
for (let i = 0; i < length; i++) {
|
|
27
|
+
bytes[i] = Math.floor(Math.random() * 256)
|
|
28
|
+
}
|
|
29
|
+
return bytes
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function createTestAction (): SerializedActionWASM {
|
|
33
|
+
return new SerializedActionWASM(
|
|
34
|
+
randomBytes(32),
|
|
35
|
+
randomBytes(32),
|
|
36
|
+
randomBytes(32),
|
|
37
|
+
randomBytes(580),
|
|
38
|
+
randomBytes(32),
|
|
39
|
+
randomBytes(64)
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function createTestAddress (): PlatformAddressWASM {
|
|
44
|
+
const addressBytes = new Uint8Array(21)
|
|
45
|
+
addressBytes[0] = 0x00
|
|
46
|
+
addressBytes.set(randomBytes(20), 1)
|
|
47
|
+
return PlatformAddressWASM.fromBytes(addressBytes)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('SerializedAction', function () {
|
|
51
|
+
let nullifier: Uint8Array
|
|
52
|
+
let rk: Uint8Array
|
|
53
|
+
let cmx: Uint8Array
|
|
54
|
+
let encryptedNote: Uint8Array
|
|
55
|
+
let cvNet: Uint8Array
|
|
56
|
+
let spendAuthSig: Uint8Array
|
|
57
|
+
|
|
58
|
+
beforeAll(function () {
|
|
59
|
+
nullifier = randomBytes(32)
|
|
60
|
+
rk = randomBytes(32)
|
|
61
|
+
cmx = randomBytes(32)
|
|
62
|
+
encryptedNote = randomBytes(580)
|
|
63
|
+
cvNet = randomBytes(32)
|
|
64
|
+
spendAuthSig = randomBytes(64)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
describe('constructor', function () {
|
|
68
|
+
test('should create SerializedAction from values', function () {
|
|
69
|
+
const action = new SerializedActionWASM(nullifier, rk, cmx, encryptedNote, cvNet, spendAuthSig)
|
|
70
|
+
|
|
71
|
+
expect(action).toBeInstanceOf(SerializedActionWASM)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('getters', function () {
|
|
76
|
+
test('should return all fields', function () {
|
|
77
|
+
const action = new SerializedActionWASM(nullifier, rk, cmx, encryptedNote, cvNet, spendAuthSig)
|
|
78
|
+
|
|
79
|
+
expect(action.nullifier).toEqual(nullifier)
|
|
80
|
+
expect(action.rk).toEqual(rk)
|
|
81
|
+
expect(action.cmx).toEqual(cmx)
|
|
82
|
+
expect(action.encryptedNote).toEqual(encryptedNote)
|
|
83
|
+
expect(action.cvNet).toEqual(cvNet)
|
|
84
|
+
expect(action.spendAuthSig).toEqual(spendAuthSig)
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
describe('setters', function () {
|
|
89
|
+
test('should set all fields', function () {
|
|
90
|
+
const action = new SerializedActionWASM(nullifier, rk, cmx, encryptedNote, cvNet, spendAuthSig)
|
|
91
|
+
|
|
92
|
+
const newNullifier = randomBytes(32)
|
|
93
|
+
const newRk = randomBytes(32)
|
|
94
|
+
const newCmx = randomBytes(32)
|
|
95
|
+
const newEncryptedNote = randomBytes(580)
|
|
96
|
+
const newCvNet = randomBytes(32)
|
|
97
|
+
const newSpendAuthSig = randomBytes(64)
|
|
98
|
+
|
|
99
|
+
action.nullifier = newNullifier
|
|
100
|
+
action.rk = newRk
|
|
101
|
+
action.cmx = newCmx
|
|
102
|
+
action.encryptedNote = newEncryptedNote
|
|
103
|
+
action.cvNet = newCvNet
|
|
104
|
+
action.spendAuthSig = newSpendAuthSig
|
|
105
|
+
|
|
106
|
+
expect(action.nullifier).toEqual(newNullifier)
|
|
107
|
+
expect(action.rk).toEqual(newRk)
|
|
108
|
+
expect(action.cmx).toEqual(newCmx)
|
|
109
|
+
expect(action.encryptedNote).toEqual(newEncryptedNote)
|
|
110
|
+
expect(action.cvNet).toEqual(newCvNet)
|
|
111
|
+
expect(action.spendAuthSig).toEqual(newSpendAuthSig)
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
describe('ShieldedTransferTransition', function () {
|
|
117
|
+
let actions: SerializedActionWASM[]
|
|
118
|
+
let valueBalance: bigint
|
|
119
|
+
let anchor: Uint8Array
|
|
120
|
+
let proof: Uint8Array
|
|
121
|
+
let bindingsSignature: Uint8Array
|
|
122
|
+
|
|
123
|
+
beforeAll(function () {
|
|
124
|
+
actions = [createTestAction()]
|
|
125
|
+
valueBalance = BigInt(100000)
|
|
126
|
+
anchor = randomBytes(32)
|
|
127
|
+
proof = randomBytes(192)
|
|
128
|
+
bindingsSignature = randomBytes(64)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
describe('constructor', function () {
|
|
132
|
+
test('should create ShieldedTransferTransition from values', function () {
|
|
133
|
+
const transition = new ShieldedTransferTransitionWASM(actions, valueBalance, anchor, proof, bindingsSignature)
|
|
134
|
+
|
|
135
|
+
expect(transition).toBeInstanceOf(ShieldedTransferTransitionWASM)
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
describe('getters', function () {
|
|
140
|
+
test('should return all fields', function () {
|
|
141
|
+
const transition = new ShieldedTransferTransitionWASM(actions, valueBalance, anchor, proof, bindingsSignature)
|
|
142
|
+
|
|
143
|
+
expect(transition.actions.length).toEqual(1)
|
|
144
|
+
expect(transition.actions[0].nullifier).toEqual(actions[0].nullifier)
|
|
145
|
+
expect(transition.valueBalance).toEqual(valueBalance)
|
|
146
|
+
expect(transition.anchor).toEqual(anchor)
|
|
147
|
+
expect(transition.proof).toEqual(proof)
|
|
148
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
describe('setters', function () {
|
|
153
|
+
test('should set all fields', function () {
|
|
154
|
+
const transition = new ShieldedTransferTransitionWASM(actions, valueBalance, anchor, proof, bindingsSignature)
|
|
155
|
+
|
|
156
|
+
const newActions = [createTestAction(), createTestAction()]
|
|
157
|
+
const newValueBalance = BigInt(200000)
|
|
158
|
+
const newAnchor = randomBytes(32)
|
|
159
|
+
const newProof = randomBytes(192)
|
|
160
|
+
const newBindingsSignature = randomBytes(64)
|
|
161
|
+
|
|
162
|
+
transition.actions = newActions
|
|
163
|
+
transition.valueBalance = newValueBalance
|
|
164
|
+
transition.anchor = newAnchor
|
|
165
|
+
transition.proof = newProof
|
|
166
|
+
transition.bindingsSignature = newBindingsSignature
|
|
167
|
+
|
|
168
|
+
expect(transition.actions.length).toEqual(2)
|
|
169
|
+
expect(transition.valueBalance).toEqual(newValueBalance)
|
|
170
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
171
|
+
expect(transition.proof).toEqual(newProof)
|
|
172
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
describe('serialization / deserialization', function () {
|
|
177
|
+
test('should roundtrip through StateTransition', function () {
|
|
178
|
+
const transition = new ShieldedTransferTransitionWASM(actions, valueBalance, anchor, proof, bindingsSignature)
|
|
179
|
+
|
|
180
|
+
const st = transition.toStateTransition()
|
|
181
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
182
|
+
|
|
183
|
+
const restored = ShieldedTransferTransitionWASM.fromStateTransition(st)
|
|
184
|
+
expect(restored).toBeInstanceOf(ShieldedTransferTransitionWASM)
|
|
185
|
+
|
|
186
|
+
expect(restored.valueBalance).toEqual(valueBalance)
|
|
187
|
+
expect(restored.anchor).toEqual(anchor)
|
|
188
|
+
expect(restored.proof).toEqual(proof)
|
|
189
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
190
|
+
expect(restored.actions.length).toEqual(1)
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
describe('ShieldTransition', function () {
|
|
196
|
+
let inputs: InputAddressWASM[]
|
|
197
|
+
let actions: SerializedActionWASM[]
|
|
198
|
+
let amount: bigint
|
|
199
|
+
let anchor: Uint8Array
|
|
200
|
+
let proof: Uint8Array
|
|
201
|
+
let bindingsSignature: Uint8Array
|
|
202
|
+
let feeStrategy: AddressFundsFeeStrategyStepWASM[]
|
|
203
|
+
let userFeeIncrease: number
|
|
204
|
+
let inputWitnesses: AddressWitnessWASM[]
|
|
205
|
+
|
|
206
|
+
beforeAll(function () {
|
|
207
|
+
const address = createTestAddress()
|
|
208
|
+
inputs = [new InputAddressWASM(address, 0, BigInt(500000))]
|
|
209
|
+
actions = [createTestAction()]
|
|
210
|
+
amount = BigInt(100000)
|
|
211
|
+
anchor = randomBytes(32)
|
|
212
|
+
proof = randomBytes(192)
|
|
213
|
+
bindingsSignature = randomBytes(64)
|
|
214
|
+
feeStrategy = [AddressFundsFeeStrategyStepWASM.DeductFromInput(0)]
|
|
215
|
+
userFeeIncrease = 0
|
|
216
|
+
inputWitnesses = [AddressWitnessWASM.P2PKH(randomBytes(65))]
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
describe('constructor', function () {
|
|
220
|
+
test('should create ShieldTransition from values', function () {
|
|
221
|
+
const transition = new ShieldTransitionWASM(
|
|
222
|
+
inputs, actions, amount, anchor, proof, bindingsSignature, feeStrategy, userFeeIncrease, inputWitnesses
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
expect(transition).toBeInstanceOf(ShieldTransitionWASM)
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
describe('getters', function () {
|
|
230
|
+
test('should return all fields', function () {
|
|
231
|
+
const transition = new ShieldTransitionWASM(
|
|
232
|
+
inputs, actions, amount, anchor, proof, bindingsSignature, feeStrategy, userFeeIncrease, inputWitnesses
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
expect(transition.inputs.length).toEqual(1)
|
|
236
|
+
expect(transition.actions.length).toEqual(1)
|
|
237
|
+
expect(transition.amount).toEqual(amount)
|
|
238
|
+
expect(transition.anchor).toEqual(anchor)
|
|
239
|
+
expect(transition.proof).toEqual(proof)
|
|
240
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
241
|
+
expect(transition.feeStrategy.length).toEqual(1)
|
|
242
|
+
expect(transition.userFeeIncrease).toEqual(userFeeIncrease)
|
|
243
|
+
expect(transition.inputWitnesses.length).toEqual(1)
|
|
244
|
+
})
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
describe('setters', function () {
|
|
248
|
+
test('should set all fields', function () {
|
|
249
|
+
const transition = new ShieldTransitionWASM(
|
|
250
|
+
inputs, actions, amount, anchor, proof, bindingsSignature, feeStrategy, userFeeIncrease, inputWitnesses
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
const newAmount = BigInt(200000)
|
|
254
|
+
const newAnchor = randomBytes(32)
|
|
255
|
+
const newProof = randomBytes(192)
|
|
256
|
+
const newBindingsSignature = randomBytes(64)
|
|
257
|
+
const newUserFeeIncrease = 5
|
|
258
|
+
|
|
259
|
+
transition.amount = newAmount
|
|
260
|
+
transition.anchor = newAnchor
|
|
261
|
+
transition.proof = newProof
|
|
262
|
+
transition.bindingsSignature = newBindingsSignature
|
|
263
|
+
transition.userFeeIncrease = newUserFeeIncrease
|
|
264
|
+
|
|
265
|
+
expect(transition.amount).toEqual(newAmount)
|
|
266
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
267
|
+
expect(transition.proof).toEqual(newProof)
|
|
268
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
269
|
+
expect(transition.userFeeIncrease).toEqual(newUserFeeIncrease)
|
|
270
|
+
})
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
describe('serialization / deserialization', function () {
|
|
274
|
+
test('should roundtrip through StateTransition', function () {
|
|
275
|
+
const transition = new ShieldTransitionWASM(
|
|
276
|
+
inputs, actions, amount, anchor, proof, bindingsSignature, feeStrategy, userFeeIncrease, inputWitnesses
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
const st = transition.toStateTransition()
|
|
280
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
281
|
+
|
|
282
|
+
const restored = ShieldTransitionWASM.fromStateTransition(st)
|
|
283
|
+
expect(restored).toBeInstanceOf(ShieldTransitionWASM)
|
|
284
|
+
|
|
285
|
+
expect(restored.amount).toEqual(amount)
|
|
286
|
+
expect(restored.anchor).toEqual(anchor)
|
|
287
|
+
expect(restored.proof).toEqual(proof)
|
|
288
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
289
|
+
expect(restored.userFeeIncrease).toEqual(userFeeIncrease)
|
|
290
|
+
expect(restored.inputs.length).toEqual(1)
|
|
291
|
+
expect(restored.actions.length).toEqual(1)
|
|
292
|
+
})
|
|
293
|
+
})
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
describe('UnshieldTransition', function () {
|
|
297
|
+
let outputAddress: PlatformAddressWASM
|
|
298
|
+
let actions: SerializedActionWASM[]
|
|
299
|
+
let unshieldingAmount: bigint
|
|
300
|
+
let anchor: Uint8Array
|
|
301
|
+
let proof: Uint8Array
|
|
302
|
+
let bindingsSignature: Uint8Array
|
|
303
|
+
|
|
304
|
+
beforeAll(function () {
|
|
305
|
+
outputAddress = createTestAddress()
|
|
306
|
+
actions = [createTestAction()]
|
|
307
|
+
unshieldingAmount = BigInt(100000)
|
|
308
|
+
anchor = randomBytes(32)
|
|
309
|
+
proof = randomBytes(192)
|
|
310
|
+
bindingsSignature = randomBytes(64)
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
describe('constructor', function () {
|
|
314
|
+
test('should create UnshieldTransition from values', function () {
|
|
315
|
+
const transition = new UnshieldTransitionWASM(
|
|
316
|
+
outputAddress, actions, unshieldingAmount, anchor, proof, bindingsSignature
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
expect(transition).toBeInstanceOf(UnshieldTransitionWASM)
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
describe('getters', function () {
|
|
324
|
+
test('should return all fields', function () {
|
|
325
|
+
const transition = new UnshieldTransitionWASM(
|
|
326
|
+
outputAddress, actions, unshieldingAmount, anchor, proof, bindingsSignature
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
expect(transition.outputAddress).toBeInstanceOf(PlatformAddressWASM)
|
|
330
|
+
expect(transition.outputAddress.bytes()).toEqual(outputAddress.bytes())
|
|
331
|
+
expect(transition.actions.length).toEqual(1)
|
|
332
|
+
expect(transition.unshieldingAmount).toEqual(unshieldingAmount)
|
|
333
|
+
expect(transition.anchor).toEqual(anchor)
|
|
334
|
+
expect(transition.proof).toEqual(proof)
|
|
335
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
336
|
+
})
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
describe('setters', function () {
|
|
340
|
+
test('should set all fields', function () {
|
|
341
|
+
const transition = new UnshieldTransitionWASM(
|
|
342
|
+
outputAddress, actions, unshieldingAmount, anchor, proof, bindingsSignature
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
const newAddress = createTestAddress()
|
|
346
|
+
const newAmount = BigInt(200000)
|
|
347
|
+
const newAnchor = randomBytes(32)
|
|
348
|
+
const newProof = randomBytes(192)
|
|
349
|
+
const newBindingsSignature = randomBytes(64)
|
|
350
|
+
|
|
351
|
+
transition.outputAddress = newAddress
|
|
352
|
+
transition.unshieldingAmount = newAmount
|
|
353
|
+
transition.anchor = newAnchor
|
|
354
|
+
transition.proof = newProof
|
|
355
|
+
transition.bindingsSignature = newBindingsSignature
|
|
356
|
+
|
|
357
|
+
expect(transition.outputAddress.bytes()).toEqual(newAddress.bytes())
|
|
358
|
+
expect(transition.unshieldingAmount).toEqual(newAmount)
|
|
359
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
360
|
+
expect(transition.proof).toEqual(newProof)
|
|
361
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
362
|
+
})
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
describe('serialization / deserialization', function () {
|
|
366
|
+
test('should roundtrip through StateTransition', function () {
|
|
367
|
+
const transition = new UnshieldTransitionWASM(
|
|
368
|
+
outputAddress, actions, unshieldingAmount, anchor, proof, bindingsSignature
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
const st = transition.toStateTransition()
|
|
372
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
373
|
+
|
|
374
|
+
const restored = UnshieldTransitionWASM.fromStateTransition(st)
|
|
375
|
+
expect(restored).toBeInstanceOf(UnshieldTransitionWASM)
|
|
376
|
+
|
|
377
|
+
expect(restored.outputAddress.bytes()).toEqual(outputAddress.bytes())
|
|
378
|
+
expect(restored.unshieldingAmount).toEqual(unshieldingAmount)
|
|
379
|
+
expect(restored.anchor).toEqual(anchor)
|
|
380
|
+
expect(restored.proof).toEqual(proof)
|
|
381
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
382
|
+
})
|
|
383
|
+
})
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
describe('ShieldFromAssetLockTransition', function () {
|
|
387
|
+
let assetLockProof: AssetLockProofWASM
|
|
388
|
+
let actions: SerializedActionWASM[]
|
|
389
|
+
let valueBalance: bigint
|
|
390
|
+
let anchor: Uint8Array
|
|
391
|
+
let proof: Uint8Array
|
|
392
|
+
let bindingsSignature: Uint8Array
|
|
393
|
+
|
|
394
|
+
beforeAll(function () {
|
|
395
|
+
const txid = 'a'.repeat(64)
|
|
396
|
+
const outPoint = new OutPointWASM(txid, 0)
|
|
397
|
+
assetLockProof = AssetLockProofWASM.createChainAssetLockProof(100, outPoint)
|
|
398
|
+
actions = [createTestAction()]
|
|
399
|
+
valueBalance = BigInt(100000)
|
|
400
|
+
anchor = randomBytes(32)
|
|
401
|
+
proof = randomBytes(192)
|
|
402
|
+
bindingsSignature = randomBytes(64)
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
describe('constructor', function () {
|
|
406
|
+
test('should create ShieldFromAssetLockTransition from values', function () {
|
|
407
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
408
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
expect(transition).toBeInstanceOf(ShieldFromAssetLockTransitionWASM)
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
test('should create ShieldFromAssetLockTransition with surplusOutput', function () {
|
|
415
|
+
const surplusOutput = createTestAddress()
|
|
416
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
417
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature, surplusOutput
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
expect(transition).toBeInstanceOf(ShieldFromAssetLockTransitionWASM)
|
|
421
|
+
expect(transition.surplusOutput).toBeInstanceOf(PlatformAddressWASM)
|
|
422
|
+
})
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
describe('getters', function () {
|
|
426
|
+
test('should return all fields', function () {
|
|
427
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
428
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature
|
|
429
|
+
)
|
|
430
|
+
|
|
431
|
+
expect(transition.assetLockProof).toBeInstanceOf(AssetLockProofWASM)
|
|
432
|
+
expect(transition.actions.length).toEqual(1)
|
|
433
|
+
expect(transition.valueBalance).toEqual(valueBalance)
|
|
434
|
+
expect(transition.anchor).toEqual(anchor)
|
|
435
|
+
expect(transition.proof).toEqual(proof)
|
|
436
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
437
|
+
})
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
describe('setters', function () {
|
|
441
|
+
test('should set all fields', function () {
|
|
442
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
443
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
const newValueBalance = BigInt(200000)
|
|
447
|
+
const newAnchor = randomBytes(32)
|
|
448
|
+
const newProof = randomBytes(192)
|
|
449
|
+
const newBindingsSignature = randomBytes(64)
|
|
450
|
+
|
|
451
|
+
transition.valueBalance = newValueBalance
|
|
452
|
+
transition.anchor = newAnchor
|
|
453
|
+
transition.proof = newProof
|
|
454
|
+
transition.bindingsSignature = newBindingsSignature
|
|
455
|
+
|
|
456
|
+
expect(transition.valueBalance).toEqual(newValueBalance)
|
|
457
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
458
|
+
expect(transition.proof).toEqual(newProof)
|
|
459
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
test('should set surplusOutput', function () {
|
|
463
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
464
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
const surplusAddress = createTestAddress()
|
|
468
|
+
transition.surplusOutput = surplusAddress
|
|
469
|
+
|
|
470
|
+
expect(transition.surplusOutput).toBeInstanceOf(PlatformAddressWASM)
|
|
471
|
+
expect(transition.surplusOutput!.bytes()).toEqual(surplusAddress.bytes())
|
|
472
|
+
})
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
describe('serialization / deserialization', function () {
|
|
476
|
+
test('should roundtrip through StateTransition', function () {
|
|
477
|
+
const transition = new ShieldFromAssetLockTransitionWASM(
|
|
478
|
+
assetLockProof, actions, valueBalance, anchor, proof, bindingsSignature
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
const st = transition.toStateTransition()
|
|
482
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
483
|
+
|
|
484
|
+
const restored = ShieldFromAssetLockTransitionWASM.fromStateTransition(st)
|
|
485
|
+
expect(restored).toBeInstanceOf(ShieldFromAssetLockTransitionWASM)
|
|
486
|
+
|
|
487
|
+
expect(restored.valueBalance).toEqual(valueBalance)
|
|
488
|
+
expect(restored.anchor).toEqual(anchor)
|
|
489
|
+
expect(restored.proof).toEqual(proof)
|
|
490
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
491
|
+
expect(restored.actions.length).toEqual(1)
|
|
492
|
+
})
|
|
493
|
+
})
|
|
494
|
+
})
|
|
495
|
+
|
|
496
|
+
describe('ShieldedWithdrawalTransition', function () {
|
|
497
|
+
let actions: SerializedActionWASM[]
|
|
498
|
+
let unshieldingAmount: bigint
|
|
499
|
+
let anchor: Uint8Array
|
|
500
|
+
let proof: Uint8Array
|
|
501
|
+
let bindingsSignature: Uint8Array
|
|
502
|
+
let coreFeePerByte: number
|
|
503
|
+
let outputScript: CoreScriptWASM
|
|
504
|
+
|
|
505
|
+
beforeAll(function () {
|
|
506
|
+
actions = [createTestAction()]
|
|
507
|
+
unshieldingAmount = BigInt(100000)
|
|
508
|
+
anchor = randomBytes(32)
|
|
509
|
+
proof = randomBytes(192)
|
|
510
|
+
bindingsSignature = randomBytes(64)
|
|
511
|
+
coreFeePerByte = 1
|
|
512
|
+
outputScript = CoreScriptWASM.newP2PKH(randomBytes(20))
|
|
513
|
+
})
|
|
514
|
+
|
|
515
|
+
describe('constructor', function () {
|
|
516
|
+
test('should create ShieldedWithdrawalTransition from values', function () {
|
|
517
|
+
const transition = new ShieldedWithdrawalTransitionWASM(
|
|
518
|
+
actions, unshieldingAmount, anchor, proof, bindingsSignature, coreFeePerByte, 'Never', outputScript
|
|
519
|
+
)
|
|
520
|
+
|
|
521
|
+
expect(transition).toBeInstanceOf(ShieldedWithdrawalTransitionWASM)
|
|
522
|
+
})
|
|
523
|
+
})
|
|
524
|
+
|
|
525
|
+
describe('getters', function () {
|
|
526
|
+
test('should return all fields', function () {
|
|
527
|
+
const transition = new ShieldedWithdrawalTransitionWASM(
|
|
528
|
+
actions, unshieldingAmount, anchor, proof, bindingsSignature, coreFeePerByte, 'Never', outputScript
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
expect(transition.actions.length).toEqual(1)
|
|
532
|
+
expect(transition.unshieldingAmount).toEqual(unshieldingAmount)
|
|
533
|
+
expect(transition.anchor).toEqual(anchor)
|
|
534
|
+
expect(transition.proof).toEqual(proof)
|
|
535
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
536
|
+
expect(transition.coreFeePerByte).toEqual(coreFeePerByte)
|
|
537
|
+
expect(transition.pooling).toEqual('Never')
|
|
538
|
+
expect(transition.outputScript).toBeInstanceOf(CoreScriptWASM)
|
|
539
|
+
})
|
|
540
|
+
})
|
|
541
|
+
|
|
542
|
+
describe('setters', function () {
|
|
543
|
+
test('should set all fields', function () {
|
|
544
|
+
const transition = new ShieldedWithdrawalTransitionWASM(
|
|
545
|
+
actions, unshieldingAmount, anchor, proof, bindingsSignature, coreFeePerByte, 'Never', outputScript
|
|
546
|
+
)
|
|
547
|
+
|
|
548
|
+
const newAmount = BigInt(200000)
|
|
549
|
+
const newAnchor = randomBytes(32)
|
|
550
|
+
const newProof = randomBytes(192)
|
|
551
|
+
const newBindingsSignature = randomBytes(64)
|
|
552
|
+
const newCoreFeePerByte = 2
|
|
553
|
+
const newOutputScript = CoreScriptWASM.newP2PKH(randomBytes(20))
|
|
554
|
+
|
|
555
|
+
transition.unshieldingAmount = newAmount
|
|
556
|
+
transition.anchor = newAnchor
|
|
557
|
+
transition.proof = newProof
|
|
558
|
+
transition.bindingsSignature = newBindingsSignature
|
|
559
|
+
transition.coreFeePerByte = newCoreFeePerByte
|
|
560
|
+
transition.pooling = 'Standard'
|
|
561
|
+
transition.outputScript = newOutputScript
|
|
562
|
+
|
|
563
|
+
expect(transition.unshieldingAmount).toEqual(newAmount)
|
|
564
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
565
|
+
expect(transition.proof).toEqual(newProof)
|
|
566
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
567
|
+
expect(transition.coreFeePerByte).toEqual(newCoreFeePerByte)
|
|
568
|
+
expect(transition.pooling).toEqual('Standard')
|
|
569
|
+
expect(transition.outputScript.bytes()).toEqual(newOutputScript.bytes())
|
|
570
|
+
})
|
|
571
|
+
})
|
|
572
|
+
|
|
573
|
+
describe('serialization / deserialization', function () {
|
|
574
|
+
test('should roundtrip through StateTransition', function () {
|
|
575
|
+
const transition = new ShieldedWithdrawalTransitionWASM(
|
|
576
|
+
actions, unshieldingAmount, anchor, proof, bindingsSignature, coreFeePerByte, 'Never', outputScript
|
|
577
|
+
)
|
|
578
|
+
|
|
579
|
+
const st = transition.toStateTransition()
|
|
580
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
581
|
+
|
|
582
|
+
const restored = ShieldedWithdrawalTransitionWASM.fromStateTransition(st)
|
|
583
|
+
expect(restored).toBeInstanceOf(ShieldedWithdrawalTransitionWASM)
|
|
584
|
+
|
|
585
|
+
expect(restored.unshieldingAmount).toEqual(unshieldingAmount)
|
|
586
|
+
expect(restored.anchor).toEqual(anchor)
|
|
587
|
+
expect(restored.proof).toEqual(proof)
|
|
588
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
589
|
+
expect(restored.coreFeePerByte).toEqual(coreFeePerByte)
|
|
590
|
+
expect(restored.pooling).toEqual('Never')
|
|
591
|
+
})
|
|
592
|
+
})
|
|
593
|
+
})
|
|
594
|
+
|
|
595
|
+
describe('IdentityCreateFromShieldedPoolTransition', function () {
|
|
596
|
+
let publicKeys: IdentityPublicKeyInCreationWASM[]
|
|
597
|
+
let denomination: bigint
|
|
598
|
+
let actions: SerializedActionWASM[]
|
|
599
|
+
let anchor: Uint8Array
|
|
600
|
+
let proof: Uint8Array
|
|
601
|
+
let bindingsSignature: Uint8Array
|
|
602
|
+
let sendToAddressOnCreationFailure: PlatformAddressWASM
|
|
603
|
+
let identityId: IdentifierWASM
|
|
604
|
+
|
|
605
|
+
beforeAll(function () {
|
|
606
|
+
publicKeys = [
|
|
607
|
+
new IdentityPublicKeyInCreationWASM(
|
|
608
|
+
0,
|
|
609
|
+
Purpose.AUTHENTICATION,
|
|
610
|
+
SecurityLevel.MASTER,
|
|
611
|
+
KeyType.ECDSA_SECP256K1,
|
|
612
|
+
false,
|
|
613
|
+
randomBytes(33)
|
|
614
|
+
)
|
|
615
|
+
]
|
|
616
|
+
denomination = BigInt(100000)
|
|
617
|
+
actions = [createTestAction()]
|
|
618
|
+
anchor = randomBytes(32)
|
|
619
|
+
proof = randomBytes(192)
|
|
620
|
+
bindingsSignature = randomBytes(64)
|
|
621
|
+
sendToAddressOnCreationFailure = createTestAddress()
|
|
622
|
+
identityId = IdentifierWASM.fromBytes(randomBytes(32))
|
|
623
|
+
})
|
|
624
|
+
|
|
625
|
+
describe('constructor', function () {
|
|
626
|
+
test('should create IdentityCreateFromShieldedPoolTransition from values', function () {
|
|
627
|
+
const transition = new IdentityCreateFromShieldedPoolTransitionWASM(
|
|
628
|
+
publicKeys, denomination, actions, anchor, proof, bindingsSignature,
|
|
629
|
+
sendToAddressOnCreationFailure, identityId
|
|
630
|
+
)
|
|
631
|
+
|
|
632
|
+
expect(transition).toBeInstanceOf(IdentityCreateFromShieldedPoolTransitionWASM)
|
|
633
|
+
})
|
|
634
|
+
})
|
|
635
|
+
|
|
636
|
+
describe('getters', function () {
|
|
637
|
+
test('should return all fields', function () {
|
|
638
|
+
const transition = new IdentityCreateFromShieldedPoolTransitionWASM(
|
|
639
|
+
publicKeys, denomination, actions, anchor, proof, bindingsSignature,
|
|
640
|
+
sendToAddressOnCreationFailure, identityId
|
|
641
|
+
)
|
|
642
|
+
|
|
643
|
+
expect(transition.publicKeys.length).toEqual(1)
|
|
644
|
+
expect(transition.denomination).toEqual(denomination)
|
|
645
|
+
expect(transition.actions.length).toEqual(1)
|
|
646
|
+
expect(transition.anchor).toEqual(anchor)
|
|
647
|
+
expect(transition.proof).toEqual(proof)
|
|
648
|
+
expect(transition.bindingsSignature).toEqual(bindingsSignature)
|
|
649
|
+
expect(transition.sendToAddressOnCreationFailure).toBeInstanceOf(PlatformAddressWASM)
|
|
650
|
+
expect(transition.sendToAddressOnCreationFailure.bytes()).toEqual(sendToAddressOnCreationFailure.bytes())
|
|
651
|
+
expect(transition.identityId).toBeInstanceOf(IdentifierWASM)
|
|
652
|
+
expect(transition.identityId.bytes()).toEqual(identityId.bytes())
|
|
653
|
+
})
|
|
654
|
+
})
|
|
655
|
+
|
|
656
|
+
describe('setters', function () {
|
|
657
|
+
test('should set all fields', function () {
|
|
658
|
+
const transition = new IdentityCreateFromShieldedPoolTransitionWASM(
|
|
659
|
+
publicKeys, denomination, actions, anchor, proof, bindingsSignature,
|
|
660
|
+
sendToAddressOnCreationFailure, identityId
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
const newDenomination = BigInt(200000)
|
|
664
|
+
const newAnchor = randomBytes(32)
|
|
665
|
+
const newProof = randomBytes(192)
|
|
666
|
+
const newBindingsSignature = randomBytes(64)
|
|
667
|
+
const newAddress = createTestAddress()
|
|
668
|
+
const newIdentityId = IdentifierWASM.fromBytes(randomBytes(32))
|
|
669
|
+
|
|
670
|
+
transition.denomination = newDenomination
|
|
671
|
+
transition.anchor = newAnchor
|
|
672
|
+
transition.proof = newProof
|
|
673
|
+
transition.bindingsSignature = newBindingsSignature
|
|
674
|
+
transition.sendToAddressOnCreationFailure = newAddress
|
|
675
|
+
transition.identityId = newIdentityId
|
|
676
|
+
|
|
677
|
+
expect(transition.denomination).toEqual(newDenomination)
|
|
678
|
+
expect(transition.anchor).toEqual(newAnchor)
|
|
679
|
+
expect(transition.proof).toEqual(newProof)
|
|
680
|
+
expect(transition.bindingsSignature).toEqual(newBindingsSignature)
|
|
681
|
+
expect(transition.sendToAddressOnCreationFailure.bytes()).toEqual(newAddress.bytes())
|
|
682
|
+
expect(transition.identityId.bytes()).toEqual(newIdentityId.bytes())
|
|
683
|
+
})
|
|
684
|
+
})
|
|
685
|
+
|
|
686
|
+
describe('serialization / deserialization', function () {
|
|
687
|
+
test('should roundtrip through StateTransition', function () {
|
|
688
|
+
const transition = new IdentityCreateFromShieldedPoolTransitionWASM(
|
|
689
|
+
publicKeys, denomination, actions, anchor, proof, bindingsSignature,
|
|
690
|
+
sendToAddressOnCreationFailure, identityId
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
const st = transition.toStateTransition()
|
|
694
|
+
expect(st).toBeInstanceOf(StateTransitionWASM)
|
|
695
|
+
|
|
696
|
+
const restored = IdentityCreateFromShieldedPoolTransitionWASM.fromStateTransition(st)
|
|
697
|
+
expect(restored).toBeInstanceOf(IdentityCreateFromShieldedPoolTransitionWASM)
|
|
698
|
+
|
|
699
|
+
expect(restored.denomination).toEqual(denomination)
|
|
700
|
+
expect(restored.anchor).toEqual(anchor)
|
|
701
|
+
expect(restored.proof).toEqual(proof)
|
|
702
|
+
expect(restored.bindingsSignature).toEqual(bindingsSignature)
|
|
703
|
+
expect(restored.publicKeys.length).toEqual(1)
|
|
704
|
+
expect(restored.actions.length).toEqual(1)
|
|
705
|
+
expect(restored.sendToAddressOnCreationFailure.bytes()).toEqual(sendToAddressOnCreationFailure.bytes())
|
|
706
|
+
expect(restored.identityId.bytes()).toEqual(identityId.bytes())
|
|
707
|
+
})
|
|
708
|
+
})
|
|
709
|
+
})
|