@cardano-sdk/e2e 0.35.0 → 0.36.0
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/.env.example +4 -0
- package/CHANGELOG.md +24 -0
- package/dist/cjs/environment.d.ts +3 -2
- package/dist/cjs/environment.d.ts.map +1 -1
- package/dist/cjs/environment.js +3 -1
- package/dist/cjs/environment.js.map +1 -1
- package/dist/cjs/factories.d.ts.map +1 -1
- package/dist/cjs/factories.js +5 -1
- package/dist/cjs/factories.js.map +1 -1
- package/dist/cjs/scripts/is-local-network-ready.js +3 -5
- package/dist/cjs/scripts/is-local-network-ready.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/util/util.d.ts +1 -1
- package/dist/cjs/util/util.d.ts.map +1 -1
- package/dist/cjs/util/util.js +7 -2
- package/dist/cjs/util/util.js.map +1 -1
- package/dist/esm/environment.d.ts +3 -2
- package/dist/esm/environment.d.ts.map +1 -1
- package/dist/esm/environment.js +3 -1
- package/dist/esm/environment.js.map +1 -1
- package/dist/esm/factories.d.ts.map +1 -1
- package/dist/esm/factories.js +5 -1
- package/dist/esm/factories.js.map +1 -1
- package/dist/esm/scripts/is-local-network-ready.js +3 -5
- package/dist/esm/scripts/is-local-network-ready.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/util/util.d.ts +1 -1
- package/dist/esm/util/util.d.ts.map +1 -1
- package/dist/esm/util/util.js +8 -3
- package/dist/esm/util/util.js.map +1 -1
- package/docker-compose.yml +1 -5
- package/jest.config.js +3 -2
- package/local-network/Dockerfile +1 -1
- package/local-network/scripts/make-babbage.sh +24 -17
- package/local-network/scripts/pools/update-node-sp1.sh +1 -1
- package/local-network/scripts/pools/update-node-sp10.sh +1 -1
- package/local-network/scripts/pools/update-node-sp11.sh +1 -1
- package/local-network/scripts/pools/update-node-sp2.sh +1 -1
- package/local-network/scripts/pools/update-node-sp3.sh +1 -1
- package/local-network/scripts/pools/update-node-sp4.sh +1 -1
- package/local-network/scripts/pools/update-node-sp5.sh +1 -1
- package/local-network/scripts/pools/update-node-sp6.sh +1 -1
- package/local-network/scripts/pools/update-node-sp7.sh +1 -1
- package/local-network/scripts/pools/update-node-sp8.sh +1 -1
- package/local-network/scripts/pools/update-node-sp9.sh +1 -1
- package/local-network/scripts/pools/update-node-utils.sh +82 -76
- package/local-network/scripts/start.sh +9 -5
- package/local-network/scripts/update-stake-pools.sh.sh +13 -0
- package/local-network/scripts/wait-local-network-init.sh +11 -0
- package/local-network/templates/babbage/alonzo-babbage-test-genesis.json +154 -154
- package/package.json +24 -21
- package/src/environment.ts +3 -1
- package/src/factories.ts +6 -1
- package/src/scripts/is-local-network-ready.ts +4 -8
- package/src/util/util.ts +12 -4
- package/test/long-running/multisig-wallet/MultiSigWallet.ts +5 -2
- package/test/long-running/shared-wallet-delegation-rewards.test.ts +2 -2
- package/test/long-running/simple-delegation-rewards.test.ts +1 -1
- package/test/{wallet → wallet_epoch_0}/PersonalWallet/byron.test.ts +1 -1
- package/test/{wallet → wallet_epoch_0}/PersonalWallet/handle.test.ts +1 -1
- package/test/{wallet → wallet_epoch_0}/PersonalWallet/mint.test.ts +7 -6
- package/test/{wallet → wallet_epoch_0}/PersonalWallet/multiAddress.test.ts +1 -1
- package/test/{wallet → wallet_epoch_0}/PersonalWallet/multisignature.test.ts +14 -11
- package/test/{wallet → wallet_epoch_0}/PersonalWallet/nft.test.ts +1 -1
- package/test/{wallet → wallet_epoch_0}/PersonalWallet/phase2validation.test.ts +2 -1
- package/test/wallet_epoch_0/PersonalWallet/plutusTest.test.ts +346 -0
- package/test/{wallet → wallet_epoch_0}/PersonalWallet/txChainHistory.test.ts +1 -1
- package/test/{wallet → wallet_epoch_0}/PersonalWallet/unspendableUtxos.test.ts +2 -2
- package/test/{wallet → wallet_epoch_0}/SharedWallet/simpleTx.test.ts +2 -2
- package/test/{wallet → wallet_epoch_3}/PersonalWallet/delegationDistribution.test.ts +2 -3
- package/test/{wallet → wallet_epoch_3}/SharedWallet/delegation.test.ts +2 -2
- package/local-network/scripts/is-db-synced.sh +0 -24
- /package/test/{wallet → wallet_epoch_0}/PersonalWallet/metadata.test.ts +0 -0
- /package/test/{wallet → wallet_epoch_0}/PersonalWallet/pouchDbWalletStores.test.ts +0 -0
- /package/test/{wallet → wallet_epoch_0}/PersonalWallet/txChaining.test.ts +0 -0
- /package/test/{wallet/SharedWallet/ultils.ts → wallet_epoch_0/SharedWallet/utils.ts} +0 -0
- /package/test/{wallet → wallet_epoch_3}/PersonalWallet/delegation.test.ts +0 -0
|
@@ -21,13 +21,16 @@ const logger = createLogger();
|
|
|
21
21
|
|
|
22
22
|
describe('PersonalWallet/mint', () => {
|
|
23
23
|
let wallet: BaseWallet;
|
|
24
|
+
let alicePolicySigner: util.KeyAgentTransactionSigner;
|
|
25
|
+
let policyScript: Cardano.NativeScript;
|
|
24
26
|
|
|
25
|
-
afterAll(() => {
|
|
27
|
+
afterAll(async () => {
|
|
28
|
+
await burnTokens({ policySigners: [alicePolicySigner], scripts: [policyScript], wallet });
|
|
26
29
|
wallet.shutdown();
|
|
27
30
|
});
|
|
28
31
|
|
|
29
32
|
it('can mint a token with no asset name', async () => {
|
|
30
|
-
wallet = (await getWallet({ env, logger, name: 'Minting Wallet'
|
|
33
|
+
wallet = (await getWallet({ env, logger, name: 'Minting Wallet' })).wallet;
|
|
31
34
|
|
|
32
35
|
const coins = 3_000_000n;
|
|
33
36
|
await walletReady(wallet, coins);
|
|
@@ -48,9 +51,9 @@ describe('PersonalWallet/mint', () => {
|
|
|
48
51
|
const alicePubKey = await aliceKeyAgent.derivePublicKey(derivationPath);
|
|
49
52
|
const aliceKeyHash = await aliceKeyAgent.bip32Ed25519.getPubKeyHash(alicePubKey);
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
alicePolicySigner = new util.KeyAgentTransactionSigner(aliceKeyAgent, derivationPath);
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
policyScript = {
|
|
54
57
|
__type: Cardano.ScriptType.Native,
|
|
55
58
|
kind: Cardano.NativeScriptKind.RequireAllOf,
|
|
56
59
|
scripts: [
|
|
@@ -118,7 +121,5 @@ describe('PersonalWallet/mint', () => {
|
|
|
118
121
|
expect(value!.assets!.has(assetId)).toBeTruthy();
|
|
119
122
|
expect(value!.assets!.get(assetId)).toBe(1n);
|
|
120
123
|
expect(txFoundInHistory.inputSource).toBe(Cardano.InputSource.inputs);
|
|
121
|
-
|
|
122
|
-
await burnTokens({ policySigners: [alicePolicySigner], scripts: [policyScript], wallet });
|
|
123
124
|
});
|
|
124
125
|
});
|
|
@@ -26,7 +26,7 @@ describe('PersonalWallet/multiAddress', () => {
|
|
|
26
26
|
let wallet: BaseWallet;
|
|
27
27
|
|
|
28
28
|
beforeAll(async () => {
|
|
29
|
-
wallet = (await getWallet({ env, idx: 0, logger, name: 'Wallet'
|
|
29
|
+
wallet = (await getWallet({ env, idx: 0, logger, name: 'Wallet' })).wallet;
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
afterAll(() => {
|
|
@@ -22,13 +22,22 @@ const logger = createLogger();
|
|
|
22
22
|
describe('PersonalWallet/multisignature', () => {
|
|
23
23
|
let wallet: BaseWallet;
|
|
24
24
|
const assetName = '3030303030';
|
|
25
|
+
let alicePolicySigner: util.KeyAgentTransactionSigner;
|
|
26
|
+
let bobPolicySigner: util.KeyAgentTransactionSigner;
|
|
27
|
+
let policyScript: Cardano.NativeScript;
|
|
28
|
+
|
|
29
|
+
afterAll(async () => {
|
|
30
|
+
await burnTokens({
|
|
31
|
+
policySigners: [alicePolicySigner, bobPolicySigner],
|
|
32
|
+
scripts: [policyScript],
|
|
33
|
+
wallet
|
|
34
|
+
});
|
|
25
35
|
|
|
26
|
-
afterAll(() => {
|
|
27
36
|
wallet.shutdown();
|
|
28
37
|
});
|
|
29
38
|
|
|
30
39
|
it('can create a transaction with multiple signatures to mint an asset', async () => {
|
|
31
|
-
wallet = (await getWallet({ env, logger, name: 'Minting Wallet'
|
|
40
|
+
wallet = (await getWallet({ env, logger, name: 'Minting Wallet' })).wallet;
|
|
32
41
|
|
|
33
42
|
const coins = 3_000_000n;
|
|
34
43
|
await walletReady(wallet, coins);
|
|
@@ -63,10 +72,10 @@ describe('PersonalWallet/multisignature', () => {
|
|
|
63
72
|
const bobPubKey = await bobKeyAgent.derivePublicKey(bobDerivationPath);
|
|
64
73
|
const bobKeyHash = await bobKeyAgent.bip32Ed25519.getPubKeyHash(bobPubKey);
|
|
65
74
|
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
alicePolicySigner = new util.KeyAgentTransactionSigner(aliceKeyAgent, aliceDerivationPath);
|
|
76
|
+
bobPolicySigner = new util.KeyAgentTransactionSigner(bobKeyAgent, bobDerivationPath);
|
|
68
77
|
|
|
69
|
-
|
|
78
|
+
policyScript = {
|
|
70
79
|
__type: Cardano.ScriptType.Native,
|
|
71
80
|
kind: Cardano.NativeScriptKind.RequireAllOf,
|
|
72
81
|
scripts: [
|
|
@@ -127,11 +136,5 @@ describe('PersonalWallet/multisignature', () => {
|
|
|
127
136
|
expect(value).toBeDefined();
|
|
128
137
|
expect(value!.assets!.has(assetId)).toBeTruthy();
|
|
129
138
|
expect(value!.assets!.get(assetId)).toBe(10n);
|
|
130
|
-
|
|
131
|
-
await burnTokens({
|
|
132
|
-
policySigners: [alicePolicySigner, bobPolicySigner],
|
|
133
|
-
scripts: [policyScript],
|
|
134
|
-
wallet
|
|
135
|
-
});
|
|
136
139
|
});
|
|
137
140
|
});
|
|
@@ -52,7 +52,7 @@ describe('PersonalWallet.assets/nft', () => {
|
|
|
52
52
|
const coins = 10_000_000n; // number of coins to use in each transaction
|
|
53
53
|
|
|
54
54
|
beforeAll(async () => {
|
|
55
|
-
wallet = (await getWallet({ env, logger, name: 'Minting Wallet'
|
|
55
|
+
wallet = (await getWallet({ env, logger, name: 'Minting Wallet' })).wallet;
|
|
56
56
|
|
|
57
57
|
await walletReady(wallet, coins);
|
|
58
58
|
|
|
@@ -18,7 +18,7 @@ const localNetworkPlutusV2CostModel = [
|
|
|
18
18
|
64_832, 32, 65_493, 32, 22_558, 32, 16_563, 32, 76_511, 32, 196_500, 453_240, 220, 0, 1, 1, 69_522, 11_687, 0, 1,
|
|
19
19
|
60_091, 32, 196_500, 453_240, 220, 0, 1, 1, 196_500, 453_240, 220, 0, 1, 1, 1_159_724, 392_670, 0, 2, 806_990, 30_482,
|
|
20
20
|
4, 1_927_926, 82_523, 4, 265_318, 0, 4, 0, 85_931, 32, 205_665, 812, 1, 1, 41_182, 32, 212_342, 32, 31_220, 32,
|
|
21
|
-
32_696, 32, 43_357, 32, 32_247, 32, 38_314, 32, 35_892_428, 10,
|
|
21
|
+
32_696, 32, 43_357, 32, 32_247, 32, 38_314, 32, 35_892_428, 10, 57_996_947, 18_975, 10, 38_887_044, 32_947, 10
|
|
22
22
|
];
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -134,6 +134,7 @@ describe('PersonalWallet/phase2validation', () => {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
]),
|
|
137
|
+
redeemersByType: { [Cardano.RedeemerPurpose.mint]: [scriptRedeemer] },
|
|
137
138
|
scriptIntegrityHash: scriptDataHash,
|
|
138
139
|
witness: { redeemers: [scriptRedeemer], scripts: [alwaysFailScript] }
|
|
139
140
|
};
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { BaseWallet } from '@cardano-sdk/wallet';
|
|
2
|
+
import { Cardano, Serialization, UtxoProvider } from '@cardano-sdk/core';
|
|
3
|
+
import { HexBlob, isNotNil } from '@cardano-sdk/util';
|
|
4
|
+
import { Observable, filter, firstValueFrom, interval, map, switchMap, take } from 'rxjs';
|
|
5
|
+
import { createLogger } from '@cardano-sdk/util-dev';
|
|
6
|
+
import { getEnv, getWallet, utxoProviderFactory, walletReady, walletVariables } from '../../../src';
|
|
7
|
+
|
|
8
|
+
const env = getEnv(walletVariables);
|
|
9
|
+
const logger = createLogger();
|
|
10
|
+
|
|
11
|
+
const scriptRedeemer: Cardano.PlutusData = {
|
|
12
|
+
constructor: 0n,
|
|
13
|
+
fields: {
|
|
14
|
+
items: [21n]
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const scriptDatum: Cardano.PlutusData = {
|
|
19
|
+
constructor: 0n,
|
|
20
|
+
fields: {
|
|
21
|
+
items: [42n]
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const midnightClaimRedeemer: Cardano.PlutusData = {
|
|
26
|
+
items: [
|
|
27
|
+
// chainCode
|
|
28
|
+
2n,
|
|
29
|
+
// grantWallet
|
|
30
|
+
new Uint8Array([
|
|
31
|
+
203, 209, 183, 104, 17, 74, 8, 166, 94, 101, 33, 139, 195, 134, 35, 246, 25, 118, 87, 49, 207, 123, 41, 139, 32,
|
|
32
|
+
144, 158, 153, 124, 40, 27, 102
|
|
33
|
+
]),
|
|
34
|
+
// rdmrGrantAmount
|
|
35
|
+
1n,
|
|
36
|
+
// grantIx
|
|
37
|
+
115n,
|
|
38
|
+
// rdmrCardanoPubKey
|
|
39
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]),
|
|
40
|
+
// rdmrMidnightKey
|
|
41
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2]),
|
|
42
|
+
// rdmrPubKey
|
|
43
|
+
new Uint8Array([
|
|
44
|
+
214, 13, 16, 28, 145, 79, 106, 83, 253, 255, 40, 69, 88, 98, 130, 102, 222, 180, 1, 144, 68, 152, 115, 119, 107,
|
|
45
|
+
51, 71, 105, 40, 115, 59, 69
|
|
46
|
+
]),
|
|
47
|
+
// rdmrSignature
|
|
48
|
+
new Uint8Array([
|
|
49
|
+
219, 89, 171, 195, 164, 168, 115, 84, 103, 158, 18, 134, 24, 127, 183, 137, 19, 50, 155, 210, 247, 198, 162, 186,
|
|
50
|
+
239, 175, 25, 248, 84, 112, 137, 228, 121, 3, 218, 45, 137, 84, 103, 130, 61, 143, 172, 133, 145, 121, 132, 10,
|
|
51
|
+
160, 14, 101, 204, 212, 12, 229, 134, 146, 67, 101, 114, 197, 31, 167, 5
|
|
52
|
+
]),
|
|
53
|
+
// hashes
|
|
54
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
|
|
55
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
|
|
56
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
|
|
57
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
|
|
58
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
|
|
59
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
|
|
60
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
|
61
|
+
]
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const midnightDatum = {
|
|
65
|
+
items: [
|
|
66
|
+
// datumClaimMask
|
|
67
|
+
340_199_290_171_201_906_221_318_119_490_500_689_920n,
|
|
68
|
+
// datumRootHash
|
|
69
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
|
70
|
+
]
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const fundScript = async (wallet: BaseWallet, receivingAddress: Cardano.PaymentAddress, datum: Cardano.PlutusData) => {
|
|
74
|
+
const tAdaToSend = 10_000_000n;
|
|
75
|
+
// Make sure the wallet has sufficient funds to run this test
|
|
76
|
+
await walletReady(wallet, tAdaToSend);
|
|
77
|
+
|
|
78
|
+
await firstValueFrom(wallet.syncStatus.isSettled$.pipe(filter((isSettled) => isSettled)));
|
|
79
|
+
|
|
80
|
+
const [{ address: sendingAddress }] = await firstValueFrom(wallet.addresses$);
|
|
81
|
+
|
|
82
|
+
logger.info(`Address ${sendingAddress} will send ${tAdaToSend} lovelace to address ${receivingAddress}.`);
|
|
83
|
+
|
|
84
|
+
// Send 10 tADA to the same wallet.
|
|
85
|
+
const txBuilder = wallet.createTxBuilder();
|
|
86
|
+
const txOutput = await txBuilder.buildOutput().address(receivingAddress).coin(tAdaToSend).datum(datum).build();
|
|
87
|
+
const signedTx = (await txBuilder.addOutput(txOutput).build().sign()).tx;
|
|
88
|
+
await wallet.submitTx(signedTx);
|
|
89
|
+
|
|
90
|
+
logger.info(
|
|
91
|
+
`Submitted transaction id: ${signedTx.id}, inputs: ${JSON.stringify(
|
|
92
|
+
signedTx.body.inputs.map((txIn) => [txIn.txId, txIn.index])
|
|
93
|
+
)} and outputs:${JSON.stringify(
|
|
94
|
+
signedTx.body.outputs.map((txOut) => [txOut.address, Number.parseInt(txOut.value.coins.toString())])
|
|
95
|
+
)}.`
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const txFoundInHistory = await firstValueFrom(
|
|
99
|
+
wallet.transactions.history$.pipe(
|
|
100
|
+
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
|
|
101
|
+
filter(isNotNil),
|
|
102
|
+
take(1)
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
logger.info(`Found transaction id in chain history: ${txFoundInHistory.id}`);
|
|
107
|
+
|
|
108
|
+
// Assert
|
|
109
|
+
expect(txFoundInHistory).toBeDefined();
|
|
110
|
+
expect(txFoundInHistory.id).toEqual(signedTx.id);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const createScriptRefInput = async (wallet: BaseWallet, script: Cardano.Script): Promise<Cardano.TxIn> => {
|
|
114
|
+
const tAdaToSend = 25_000_000n;
|
|
115
|
+
// Use dummy address to position the reference script
|
|
116
|
+
const refScriptAddress = Cardano.PaymentAddress(
|
|
117
|
+
'addr_test1qqt9c69kjqf0wsnlp7hs8xees5l6pm4yxdqa3hknqr0kfe0htmj4e5t8n885zxm4qzpfzwruqx3ey3f5q8kpkr0gt9ms8dcsz6'
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
// Make sure the wallet has sufficient funds to run this test
|
|
121
|
+
await walletReady(wallet, tAdaToSend);
|
|
122
|
+
|
|
123
|
+
await firstValueFrom(wallet.syncStatus.isSettled$.pipe(filter((isSettled) => isSettled)));
|
|
124
|
+
|
|
125
|
+
const [{ address: sendingAddress }] = await firstValueFrom(wallet.addresses$);
|
|
126
|
+
|
|
127
|
+
logger.info(`Address ${sendingAddress} will send ${tAdaToSend} lovelace to address ${refScriptAddress}.`);
|
|
128
|
+
|
|
129
|
+
const txBuilder = wallet.createTxBuilder();
|
|
130
|
+
const txOutput = await txBuilder
|
|
131
|
+
.buildOutput()
|
|
132
|
+
.address(refScriptAddress)
|
|
133
|
+
.coin(tAdaToSend)
|
|
134
|
+
.scriptReference(script)
|
|
135
|
+
.build();
|
|
136
|
+
|
|
137
|
+
const signedTx = (await txBuilder.addOutput(txOutput).build().sign()).tx;
|
|
138
|
+
await wallet.submitTx(signedTx);
|
|
139
|
+
|
|
140
|
+
logger.info(
|
|
141
|
+
`Submitted transaction id: ${signedTx.id}, inputs: ${JSON.stringify(
|
|
142
|
+
signedTx.body.inputs.map((txIn) => [txIn.txId, txIn.index])
|
|
143
|
+
)} and outputs:${JSON.stringify(
|
|
144
|
+
signedTx.body.outputs.map((txOut) => [txOut.address, Number.parseInt(txOut.value.coins.toString())])
|
|
145
|
+
)}.`
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const txFoundInHistory = await firstValueFrom(
|
|
149
|
+
wallet.transactions.history$.pipe(
|
|
150
|
+
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
|
|
151
|
+
filter(isNotNil),
|
|
152
|
+
take(1)
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
logger.info(`Found transaction id in chain history: ${txFoundInHistory.id}`);
|
|
157
|
+
|
|
158
|
+
// Assert
|
|
159
|
+
expect(txFoundInHistory).toBeDefined();
|
|
160
|
+
expect(txFoundInHistory.id).toEqual(signedTx.id);
|
|
161
|
+
|
|
162
|
+
const index = signedTx.body.outputs.findIndex((out) => !!out.scriptReference);
|
|
163
|
+
|
|
164
|
+
return { index, txId: signedTx.id };
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const getScriptUtxoSet = (
|
|
168
|
+
poolingInterval: number,
|
|
169
|
+
utxoProvider: UtxoProvider,
|
|
170
|
+
scriptAddress: Cardano.PaymentAddress
|
|
171
|
+
): Observable<Cardano.Utxo[]> =>
|
|
172
|
+
interval(poolingInterval).pipe(
|
|
173
|
+
switchMap(
|
|
174
|
+
() =>
|
|
175
|
+
new Observable<Cardano.Utxo[]>((subscriber) => {
|
|
176
|
+
utxoProvider
|
|
177
|
+
.utxoByAddresses({ addresses: [scriptAddress] })
|
|
178
|
+
// eslint-disable-next-line promise/always-return
|
|
179
|
+
.then((utxos) => {
|
|
180
|
+
subscriber.next(utxos);
|
|
181
|
+
})
|
|
182
|
+
.catch((error) => subscriber.error(error));
|
|
183
|
+
})
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
describe('PersonalWallet/plutus', () => {
|
|
188
|
+
let wallet: BaseWallet;
|
|
189
|
+
afterAll(() => {
|
|
190
|
+
wallet.shutdown();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('can spend balance from a plutus script', async () => {
|
|
194
|
+
wallet = (await getWallet({ env, logger, name: 'Spending Wallet', polling: { interval: 50 } })).wallet;
|
|
195
|
+
// UTXO provider can be use to fetch the UTXO set from the script address.
|
|
196
|
+
const utxoProvider = await utxoProviderFactory.create(env.UTXO_PROVIDER, env.UTXO_PROVIDER_PARAMS, logger);
|
|
197
|
+
|
|
198
|
+
// Plutus script that always returns true.
|
|
199
|
+
const alwaysSucceedsScript: Cardano.PlutusScript = {
|
|
200
|
+
__type: Cardano.ScriptType.Plutus,
|
|
201
|
+
bytes: HexBlob(
|
|
202
|
+
'59079201000033232323232323232323232323232332232323232323232222232325335333006300800530070043333573466E1CD55CEA80124000466442466002006004646464646464646464646464646666AE68CDC39AAB9D500C480008CCCCCCCCCCCC88888888888848CCCCCCCCCCCC00403403002C02802402001C01801401000C008CD4060064D5D0A80619A80C00C9ABA1500B33501801A35742A014666AA038EB9406CD5D0A804999AA80E3AE501B35742A01066A0300466AE85401CCCD54070091D69ABA150063232323333573466E1CD55CEA801240004664424660020060046464646666AE68CDC39AAB9D5002480008CC8848CC00400C008CD40B9D69ABA15002302F357426AE8940088C98C80C8CD5CE01981901809AAB9E5001137540026AE854008C8C8C8CCCD5CD19B8735573AA004900011991091980080180119A8173AD35742A004605E6AE84D5D1280111931901919AB9C033032030135573CA00226EA8004D5D09ABA2500223263202E33573805E05C05826AAE7940044DD50009ABA1500533501875C6AE854010CCD540700808004D5D0A801999AA80E3AE200135742A00460446AE84D5D1280111931901519AB9C02B02A028135744A00226AE8940044D5D1280089ABA25001135744A00226AE8940044D5D1280089ABA25001135744A00226AE8940044D55CF280089BAA00135742A00460246AE84D5D1280111931900E19AB9C01D01C01A101B13263201B3357389201035054350001B135573CA00226EA80054049404448C88C008DD6000990009AA80A911999AAB9F0012500A233500930043574200460066AE880080548C8C8CCCD5CD19B8735573AA004900011991091980080180118061ABA150023005357426AE8940088C98C8054CD5CE00B00A80989AAB9E5001137540024646464646666AE68CDC39AAB9D5004480008CCCC888848CCCC00401401000C008C8C8C8CCCD5CD19B8735573AA0049000119910919800801801180A9ABA1500233500F014357426AE8940088C98C8068CD5CE00D80D00C09AAB9E5001137540026AE854010CCD54021D728039ABA150033232323333573466E1D4005200423212223002004357426AAE79400C8CCCD5CD19B875002480088C84888C004010DD71ABA135573CA00846666AE68CDC3A801A400042444006464C6403866AE700740700680640604D55CEA80089BAA00135742A00466A016EB8D5D09ABA2500223263201633573802E02C02826AE8940044D5D1280089AAB9E500113754002266AA002EB9D6889119118011BAB00132001355012223233335573E0044A010466A00E66442466002006004600C6AAE754008C014D55CF280118021ABA200301313574200222440042442446600200800624464646666AE68CDC3A800A40004642446004006600A6AE84D55CF280191999AB9A3370EA0049001109100091931900899AB9C01201100F00E135573AA00226EA80048C8C8CCCD5CD19B875001480188C848888C010014C01CD5D09AAB9E500323333573466E1D400920042321222230020053009357426AAE7940108CCCD5CD19B875003480088C848888C004014C01CD5D09AAB9E500523333573466E1D40112000232122223003005375C6AE84D55CF280311931900899AB9C01201100F00E00D00C135573AA00226EA80048C8C8CCCD5CD19B8735573AA004900011991091980080180118029ABA15002375A6AE84D5D1280111931900699AB9C00E00D00B135573CA00226EA80048C8CCCD5CD19B8735573AA002900011BAE357426AAE7940088C98C802CCD5CE00600580489BAA001232323232323333573466E1D4005200C21222222200323333573466E1D4009200A21222222200423333573466E1D400D2008233221222222233001009008375C6AE854014DD69ABA135744A00A46666AE68CDC3A8022400C4664424444444660040120106EB8D5D0A8039BAE357426AE89401C8CCCD5CD19B875005480108CC8848888888CC018024020C030D5D0A8049BAE357426AE8940248CCCD5CD19B875006480088C848888888C01C020C034D5D09AAB9E500B23333573466E1D401D2000232122222223005008300E357426AAE7940308C98C8050CD5CE00A80A00900880800780700680609AAB9D5004135573CA00626AAE7940084D55CF280089BAA0012323232323333573466E1D400520022333222122333001005004003375A6AE854010DD69ABA15003375A6AE84D5D1280191999AB9A3370EA0049000119091180100198041ABA135573CA00C464C6401A66AE7003803402C0284D55CEA80189ABA25001135573CA00226EA80048C8C8CCCD5CD19B875001480088C8488C00400CDD71ABA135573CA00646666AE68CDC3A8012400046424460040066EB8D5D09AAB9E500423263200A33573801601401000E26AAE7540044DD500089119191999AB9A3370EA00290021091100091999AB9A3370EA00490011190911180180218031ABA135573CA00846666AE68CDC3A801A400042444004464C6401666AE7003002C02402001C4D55CEA80089BAA0012323333573466E1D40052002212200223333573466E1D40092000212200123263200733573801000E00A00826AAE74DD5000891999AB9A3370E6AAE74DD5000A40004008464C6400866AE700140100092612001490103505431001123230010012233003300200200122212200201'
|
|
203
|
+
),
|
|
204
|
+
version: Cardano.PlutusLanguageVersion.V2
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const scriptHash = Serialization.Script.fromCore(alwaysSucceedsScript).hash();
|
|
208
|
+
const scriptAddress = Cardano.EnterpriseAddress.fromCredentials(Cardano.NetworkId.Testnet, {
|
|
209
|
+
hash: scriptHash,
|
|
210
|
+
type: Cardano.CredentialType.ScriptHash
|
|
211
|
+
})
|
|
212
|
+
.toAddress()
|
|
213
|
+
.toBech32() as Cardano.PaymentAddress;
|
|
214
|
+
|
|
215
|
+
await fundScript(wallet, scriptAddress, scriptDatum);
|
|
216
|
+
await walletReady(wallet);
|
|
217
|
+
|
|
218
|
+
const scriptUtxos = await firstValueFrom(getScriptUtxoSet(50, utxoProvider, scriptAddress));
|
|
219
|
+
const bigScriptUtxo = scriptUtxos.find((utxo) => utxo[1].value.coins === 10_000_000n);
|
|
220
|
+
expect(bigScriptUtxo).toBeDefined();
|
|
221
|
+
const [{ address: receivingAddress }] = await firstValueFrom(wallet.addresses$);
|
|
222
|
+
|
|
223
|
+
const txBuilder = wallet.createTxBuilder();
|
|
224
|
+
const txOutput = await txBuilder.buildOutput().address(receivingAddress).coin(10_000_000n).build();
|
|
225
|
+
|
|
226
|
+
const signedTx = (
|
|
227
|
+
await txBuilder
|
|
228
|
+
.addInput(bigScriptUtxo!, {
|
|
229
|
+
datum: scriptDatum,
|
|
230
|
+
redeemer: scriptRedeemer,
|
|
231
|
+
script: alwaysSucceedsScript
|
|
232
|
+
})
|
|
233
|
+
.addOutput(txOutput)
|
|
234
|
+
.setValidityInterval({
|
|
235
|
+
invalidBefore: undefined,
|
|
236
|
+
invalidHereafter: undefined // HACK: setting any valid interval cause an error in the node: Uncomputable slot arithmetic; transaction's validity bounds go beyond the foreseeable end of the current era
|
|
237
|
+
})
|
|
238
|
+
.build()
|
|
239
|
+
.sign()
|
|
240
|
+
).tx;
|
|
241
|
+
|
|
242
|
+
await wallet.submitTx(signedTx);
|
|
243
|
+
|
|
244
|
+
logger.info(
|
|
245
|
+
`Submitted transaction id: ${signedTx.id}, inputs: ${JSON.stringify(
|
|
246
|
+
signedTx.body.inputs.map((txIn) => [txIn.txId, txIn.index])
|
|
247
|
+
)} and outputs:${JSON.stringify(
|
|
248
|
+
signedTx.body.outputs.map((txOut) => [txOut.address, Number.parseInt(txOut.value.coins.toString())])
|
|
249
|
+
)}.`
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const txFoundInHistory = await firstValueFrom(
|
|
253
|
+
wallet.transactions.history$.pipe(
|
|
254
|
+
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
|
|
255
|
+
filter(isNotNil),
|
|
256
|
+
take(1)
|
|
257
|
+
)
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
logger.info(`Found transaction id in chain history: ${txFoundInHistory.id}`);
|
|
261
|
+
|
|
262
|
+
// Assert
|
|
263
|
+
expect(txFoundInHistory).toBeDefined();
|
|
264
|
+
expect(txFoundInHistory.id).toEqual(signedTx.id);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('can spend balance from a plutus script using a reference script', async () => {
|
|
268
|
+
wallet = (await getWallet({ env, logger, name: 'Spending Wallet', polling: { interval: 50 } })).wallet;
|
|
269
|
+
// UTXO provider can be use to fetch the UTXO set from the script address.
|
|
270
|
+
const utxoProvider = await utxoProviderFactory.create(env.UTXO_PROVIDER, env.UTXO_PROVIDER_PARAMS, logger);
|
|
271
|
+
|
|
272
|
+
const midnightClaimScript: Cardano.PlutusScript = {
|
|
273
|
+
__type: Cardano.ScriptType.Plutus,
|
|
274
|
+
bytes: HexBlob(
|
|
275
|
+
'59141d0100003333323233223322332232323232323232332232323232323232323232323232323232323232323232323232323232323232323222222223232323232323232323230012222223501422350102232323232533500910471533501522221323001225335500b1304d490101680015335323253350021001105332325335002100110545335014105415335330312350012222330443500422002304e02c500c1304f4910163002213500222225335005153335304b0021305549101640021323253350021001105c33023490101660032325335305c330380020011533533034002001105d105e105d33302301a01900c33304f75ca09c00a6604492101650035533530270011305649010131002215335001130584910131002215335001133064375c0086eb8008884c17124101310022350102253353304b00400213304b003001105e21305649010164002213057491013900532335330312350012222355010222235004223500a2232335005233500425333573466e3c0080045400c418c818c8cd4010818c94ccd5cd19b8f0020011500310631533500321533500221335002233500223305000200122206622233500420662225333573466e1c01800c54ccd5cd19b8700500213304000400110681068106115335001210611061500c153353302b500133702605266e00c0a4cc0b044888d400488cc01400401002120024800841504c13d24010136002213500222225335005153335304b0021305549101370021323253350021001105c3302349010161003303233304f75ca09c00a646460b06607000400264660b660b6466e09200100100133302301a01900c3550132222003330224901013800533532323500222350032232325335002100110623304e0040023303800400233050500901653353027001130564910131002215335001130584910131002215335001133053375a0086eb8008884c171241013100105b101e213056490101370022130574910139001530172222223500d2233553355335007105b1333011300c223500222372466e28cdc519b8a0020014890123003730607e0060020042a666ae68cdc4000a40002a0a2264a666ae68cdc419b860173370490020008008982999b800170011505230300011505121001130564901013500330194910162005335013105213500422323253350021001105535005223253353001489016300133044002372800c2a66a6002911016200133044002372400c2640b06002910101650030430023335734666e54008c01488d400888d402c88cdc519b8a337146e60c0e801401000ccdc500100080082a029882709826a481016a0050041533550041533533022330231122322300200130532253350011003221330060023004001500348008411c4c1192410168001304649101680030502222533500113303a0030082215333573466e1d20003370c008900209998031982400280119b84004480100044ccc018cc120008014cdc2002240080022a66a601c6aa02244444400c426a00244646464a666ae68cdc3a4000004264646666444424666600200a008006004607c6ae8400cccc111d728219aba100230423574200266082eb8d5d09aba2001357440026ae880044c1292401035054310035573c0046aae74004dd5000898222490134001355010222222004153350061046135500f222222350022235002225323335003215333573466e20094c8cdc099b8048008008004c0f400c414c4c00926130014984c005262350042253335002215333573466e2009cc8cdc019b8100248008004c0fc0084c141240101670010541304f4910167001304f49101670050103041225335001150332215350022233532350032235003225333573466e3c0100084ccd5cd19b870030010460451045355009222222333350012304349010133002304349101330023043491013300200113038004130060032223233001330430043300133043003002040040503e225335001103b133573800407426a002446a0044444444444442466666600201a00a01600600c01c646464a666ae68cdc3a4000004266442466002006004646464a666ae68cdc3a40000042646464646464646464646666666666664444444444442466666666666600201a01801601401201000e00c00a008006004660284646464a666ae68cdc3a400000426644246600200600460686ae84004d5d09aba200113046491035054310035573c0046aae74004dd50009aba100b35742014660284646464a666ae68cdc3a4000004264646666444424666600200a00800600460746ae8400cd5d08011aba1001357426ae88004d5d10009aba2001130464901035054310035573c0046aae74004dd50009aba1009357420106ae8401cd5d08031aba10053232325333573466e1d20000021332212330010030023232325333573466e1d20000021332212330010030023303575a6ae84004c0d0d5d09aba2001130484901035054310035573c0046aae74004dd51aba10013232325333573466e1d20000021332212330010030023303575a6ae84004c0d0d5d09aba2001130484901035054310035573c0046aae74004dd51aba1357440022608a921035054310035573c0046aae74004dd51aba10043301475c6ae8400cd5d08011aba1001357426ae88004d5d10009aba2001357440026ae88004d5d10009aba2001357440026ae88004d5d10009aba200113038491035054310035573c0046aae74004dd51aba10013232325333573466e1d2000002132122223003005375c6ae8400454ccd5cd19b87480080084c848888c004014c098d5d08008a999ab9a3370e900200109909111180100298159aba100115333573466e1d20060021321222230040053232325333573466e1d2000002132122222223005008302e357420022a666ae68cdc3a400400426424444444600e010605c6ae8400454ccd5cd19b87480100084cc8848888888cc018024020c0b8d5d08009bae357426ae8800454ccd5cd19b87480180084cc8848888888cc008024020dd71aba1001375c6ae84d5d10008a999ab9a3370e90040010999109111111198008048041bae357420026eb4d5d09aba200115333573466e1d200a00211222222200415333573466e1d200c0021122222220031303b491035054310035573c0046aae74004dd51aba1001130384901035054310035573c0046aae74004dd51aba1357440022606a921035054310035573c0046aae74004dd5002a99a98010028891000910a99a80089819a4901320022153350011303549101320022153350011303749101320022153350011303949101320022153350011303b49101320022153350011303d49101320022153350011303f49101320022132323333222212233330020060050040033304d3304d5333573466e1d20000011488101620015333573466e1d2002001148810165001489016300375c020a666ae68cdc40012400426086920101320010023304d3041003375a0186609a6eb8028dd7004198269bae006375c0086eb4044dd6806299a980080289818249013100221533500113032491013100221533500113302d375a0086eb8008884c0d9241013100300120012322300237580026074446666aae7c00480e48cd40e0c010d5d080118019aba20020323031225333573466e2400520c00115333573466e2400520800115333573466e24005204015333573466e24005202015333573466e24005201015333573466e1d20100011482001054ccd5cd19b8748038004520800215333573466e1d200c0011482000454ccd5cd19b87480280045204015333573466e1d200800114808054ccd5cd19b87480180045201015333573466e1d200400114802054ccd5cd19b87480080045200415333573466e1d20000011480084cdc11919b820010013002337080029002199ab9a3370e900119b86001480112004480084cdc12410008600466e04005201013370490404004180119b81001480804cdc12410101010040600466e0400520401337049040404040404040404002180119b8100148200044cdc12410101010101010101010101010080600466e0400520c0012233323300123007001330012333573466e1d200000102e02d00423232232223300300200130362225335002130050012215335003130080042213500422323500522533533028005002153353300d00400113300c008006103b15335301000413300c00800a13300353353010001103e133503d00703e006303f2225335001103b221350022253353014001133007006003153353302c009002153353301100800113301000c3330462225335002100122133005001335046002003006003103f133007335041004006003303422533500110302213500222533530080011300600310333033225335001102f22135002225335300700113006003103200200122333573466e1c0080040ac0a88cd5400488cdc0240040029000181691299a80088149109a801112999ab9a3370e9000000898030018816111801999a80200a001000981591299a800881491099a8151a8011119818001199a8009180500091199a80480c80100091805800980200089911119191981811299a800880191099a8178011802000980100218029980311a80091911801003981891299a80088169109a80111299a99806001003881809803001801181711299a800881611099a8169a80111191981a0019800804181a11299a80089aa8198019109a80111299a998078010040891119801005002098030019802000981511299a800881411099a8149a80111198178011817000980200091911801000981511299a800881411099299a9803001899a81500180088009802000981411299a800881311099a8139a801111981680118160009802000981391299a800881291099a8131a80111198160011aa815000980200091801199802a4000002046604a4466a00292100225335001100222135325333573466e24005200013302b028006133500900100633706600e00a90021119b96300800230080013024225335001148000884cdc02400460080026604644244a66a00226604c046046442a666ae68cdc3a400400826605066a04800404a00226a66a600c2400266e040112002001223302a3350260040020011200130222225333573466e20005200012335021491012d003330040033370290000010008980219802810800981091299a8008900091099119a8112999ab9a3370e90000020a4901300015333573466e1d20020041490101310015333573466e1d20040041490101320015333573466e1d20060041490101330015333573466e1d20080041490101340015333573466e1d200a0041490101350015333573466e1d200c0041490101360015333573466e1d200e0041490101370015333573466e1d2010004149010138001333573466e1d2012004490101390049010f3c696e76616c69642064696769743e00300200130040013020222325333573466e1d2000001133501f3370a004900a00189980219a80f99b850024805000c004cdc2000a40284646464a666ae68cdc3a400000420382a666ae68cdc3a4004004203a26030921035054310035573c0046aae74004dd5000911919192999ab9a3370e9000001089110010a999ab9a3370e90010010990911180180218029aba100115333573466e1d20040021122200113018491035054310035573c0046aae74004dd500091919192999ab9a3370e90000010999109198008018011919192999ab9a3370e900000109bae3574200226032921035054310035573c0046aae74004dd51aba1001375a6ae84d5d10008980b2481035054310035573c0046aae74004dd5000919a800a400490001119a801119a801119802801000900c119a801100c11980280100091199ab9a3371e00400202c02a4646464a666ae68cdc3a4000004266442466002006004600c6ae84004cc01c014d5d09aba2001130124901035054310035573c0046aae74004dd500091919192999ab9a3370e9000001099091180100198029aba100115333573466e1d2002002132333222122333001005004003375a6ae84008dd69aba1001375a6ae84d5d10009aba2001130114901035054310035573c0046aae74004dd500091919192999ab9a3370e900000109909118010019bae357420022a666ae68cdc3a4004004260146eb8d5d0800898082481035054310035573c0046aae74004dd5000911919192999ab9a3370e90010010a8058a999ab9a3370e90000010980618029aba1001130104901035054310035573c0046aae74004dd500091919192999ab9a3370e9000001089110018a999ab9a3370e9001001099091118008021bae357420022a666ae68cdc3a4008004264244460040086ae840044c0392401035054310035573c0046aae74004dd5000899800bae75a4464460046eac004c05488cccd55cf800900a11919a80a1980c18031aab9d001300535573c00260086ae8800cd5d080100691091980080180110911800801909118010018891000911b9233714004002601a44a66a002201644266a0186eb8008c010004c030894cd40044028884cd402cd400888cc044008cc0248ccd40048cdc0240000024466e000080048cdc0240000020026008002464c66ae70004008480048c88c008004c028894cd40044020884cd4024d400888cc03c008c01c004c010004c020894cd4004401088c84d400c88c00c004c030894cd40044c01800c884d4008894ccd40048ccd5cd19b884800000440304c01c01088ccd5cd19b88002001100d130080052333573466e200052000100c1300700412200212200112200212212233001004003212223003004112122230010042212330010030022323001001223300330020020013335122233333351222333335122002222222123333330010070060050040030022001005006002122002122001200100200300312200212200120014891c5c6dfd90190d6c66547da3debf3d8967340b270feb3f6cf5a5f8cab80048373df7bcbd18ccd54cd4488008448848cc00400c0084480052211cd441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf004881054e494748540001'
|
|
276
|
+
),
|
|
277
|
+
version: Cardano.PlutusLanguageVersion.V2
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// 1.- Create reference script input
|
|
281
|
+
const scriptRefInput = await createScriptRefInput(wallet, midnightClaimScript);
|
|
282
|
+
const scriptHash = Serialization.Script.fromCore(midnightClaimScript).hash();
|
|
283
|
+
const scriptAddress = Cardano.EnterpriseAddress.fromCredentials(Cardano.NetworkId.Testnet, {
|
|
284
|
+
hash: scriptHash,
|
|
285
|
+
type: Cardano.CredentialType.ScriptHash
|
|
286
|
+
})
|
|
287
|
+
.toAddress()
|
|
288
|
+
.toBech32() as Cardano.PaymentAddress;
|
|
289
|
+
|
|
290
|
+
// 2.- Fund script address
|
|
291
|
+
await fundScript(wallet, scriptAddress, midnightDatum);
|
|
292
|
+
await walletReady(wallet);
|
|
293
|
+
|
|
294
|
+
// 3.- Spend the UTXO and lock the value back in to the script.
|
|
295
|
+
const scriptUtxos = await firstValueFrom(getScriptUtxoSet(50, utxoProvider, scriptAddress));
|
|
296
|
+
const bigScriptUtxo = scriptUtxos.find((utxo) => utxo[1].value.coins === 10_000_000n);
|
|
297
|
+
expect(bigScriptUtxo).toBeDefined();
|
|
298
|
+
|
|
299
|
+
const txBuilder = wallet.createTxBuilder();
|
|
300
|
+
const txOutput = await txBuilder
|
|
301
|
+
.buildOutput()
|
|
302
|
+
.address(scriptAddress)
|
|
303
|
+
.datum(midnightDatum)
|
|
304
|
+
.coin(10_000_000n)
|
|
305
|
+
.build();
|
|
306
|
+
|
|
307
|
+
const signedTx = (
|
|
308
|
+
await txBuilder
|
|
309
|
+
.addInput(bigScriptUtxo!, {
|
|
310
|
+
redeemer: midnightClaimRedeemer
|
|
311
|
+
})
|
|
312
|
+
.addReferenceInput(scriptRefInput)
|
|
313
|
+
.addOutput(txOutput)
|
|
314
|
+
.setValidityInterval({
|
|
315
|
+
invalidBefore: undefined,
|
|
316
|
+
invalidHereafter: undefined // HACK: setting any valid interval cause an error in the node: Uncomputable slot arithmetic; transaction's validity bounds go beyond the foreseeable end of the current era
|
|
317
|
+
})
|
|
318
|
+
.build()
|
|
319
|
+
.sign()
|
|
320
|
+
).tx;
|
|
321
|
+
|
|
322
|
+
await wallet.submitTx(signedTx);
|
|
323
|
+
|
|
324
|
+
logger.info(
|
|
325
|
+
`Submitted transaction id: ${signedTx.id}, inputs: ${JSON.stringify(
|
|
326
|
+
signedTx.body.inputs.map((txIn) => [txIn.txId, txIn.index])
|
|
327
|
+
)} and outputs:${JSON.stringify(
|
|
328
|
+
signedTx.body.outputs.map((txOut) => [txOut.address, Number.parseInt(txOut.value.coins.toString())])
|
|
329
|
+
)}.`
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
const txFoundInHistory = await firstValueFrom(
|
|
333
|
+
wallet.transactions.history$.pipe(
|
|
334
|
+
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
|
|
335
|
+
filter(isNotNil),
|
|
336
|
+
take(1)
|
|
337
|
+
)
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
logger.info(`Found transaction id in chain history: ${txFoundInHistory.id}`);
|
|
341
|
+
|
|
342
|
+
// Assert
|
|
343
|
+
expect(txFoundInHistory).toBeDefined();
|
|
344
|
+
expect(txFoundInHistory.id).toEqual(signedTx.id);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
@@ -12,7 +12,7 @@ describe('PersonalWallet/txChainHistory', () => {
|
|
|
12
12
|
let signedTx: Cardano.Tx<Cardano.TxBody>;
|
|
13
13
|
|
|
14
14
|
beforeEach(async () => {
|
|
15
|
-
({ wallet } = await getWallet({ env, logger, name: 'Sending Wallet'
|
|
15
|
+
({ wallet } = await getWallet({ env, logger, name: 'Sending Wallet' }));
|
|
16
16
|
const tAdaToSend = 10_000_000n;
|
|
17
17
|
// Make sure the wallet has sufficient funds to run this test
|
|
18
18
|
await walletReady(wallet, tAdaToSend);
|
|
@@ -21,8 +21,8 @@ describe('PersonalWallet/unspendableUtxos', () => {
|
|
|
21
21
|
// eslint-disable-next-line max-statements
|
|
22
22
|
it.skip('unsets unspendable UTxOs when no longer in the wallets UTxO set', async () => {
|
|
23
23
|
// Here we will simulate the scenario of collateral consumption by spending it from another wallet instance.
|
|
24
|
-
wallet1 = (await getWallet({ env, logger, name: 'Wallet 1'
|
|
25
|
-
wallet2 = (await getWallet({ env, logger, name: 'Wallet 2'
|
|
24
|
+
wallet1 = (await getWallet({ env, logger, name: 'Wallet 1' })).wallet;
|
|
25
|
+
wallet2 = (await getWallet({ env, logger, name: 'Wallet 2' })).wallet;
|
|
26
26
|
|
|
27
27
|
const coins = 5_000_000n;
|
|
28
28
|
await walletReady(wallet1, coins);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseWallet } from '@cardano-sdk/wallet';
|
|
2
2
|
import { Cardano } from '@cardano-sdk/core';
|
|
3
|
-
import { buildSharedWallets } from './
|
|
3
|
+
import { buildSharedWallets } from './utils';
|
|
4
4
|
import { filter, firstValueFrom, map, take } from 'rxjs';
|
|
5
5
|
import {
|
|
6
6
|
getEnv,
|
|
@@ -25,7 +25,7 @@ describe('SharedWallet/simpleTx', () => {
|
|
|
25
25
|
const initialFunds = 10_000_000n;
|
|
26
26
|
|
|
27
27
|
beforeAll(async () => {
|
|
28
|
-
({ wallet: faucetWallet } = await getWallet({ env, logger, name: 'Sending Wallet'
|
|
28
|
+
({ wallet: faucetWallet } = await getWallet({ env, logger, name: 'Sending Wallet' }));
|
|
29
29
|
|
|
30
30
|
// Make sure the wallet has sufficient funds to run this test
|
|
31
31
|
await walletReady(faucetWallet, initialFunds);
|
|
@@ -25,8 +25,7 @@ const fundWallet = async (wallet: BaseWallet) => {
|
|
|
25
25
|
logger.info(
|
|
26
26
|
`Insufficient funds in wallet account index 1. Missing ${coinDeficit}. Transferring from wallet account index 0`
|
|
27
27
|
);
|
|
28
|
-
const fundingWallet = (await getWallet({ env, idx: 0, logger, name: 'WalletAcct0'
|
|
29
|
-
.wallet;
|
|
28
|
+
const fundingWallet = (await getWallet({ env, idx: 0, logger, name: 'WalletAcct0' })).wallet;
|
|
30
29
|
await walletReady(fundingWallet);
|
|
31
30
|
const fundingTxBuilder = fundingWallet.createTxBuilder();
|
|
32
31
|
const { tx } = await fundingTxBuilder
|
|
@@ -125,7 +124,7 @@ describe('PersonalWallet/delegationDistribution', () => {
|
|
|
125
124
|
let wallet: BaseWallet;
|
|
126
125
|
|
|
127
126
|
beforeAll(async () => {
|
|
128
|
-
wallet = (await getWallet({ env, idx: 3, logger, name: 'Wallet'
|
|
127
|
+
wallet = (await getWallet({ env, idx: 3, logger, name: 'Wallet' })).wallet;
|
|
129
128
|
await fundWallet(wallet);
|
|
130
129
|
await deregisterAllStakeKeys(wallet);
|
|
131
130
|
});
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
walletReady,
|
|
13
13
|
walletVariables
|
|
14
14
|
} from '../../../src';
|
|
15
|
-
import { buildSharedWallets } from '
|
|
15
|
+
import { buildSharedWallets } from '../../wallet_epoch_0/SharedWallet/utils';
|
|
16
16
|
import { combineLatest, filter, firstValueFrom, map, take } from 'rxjs';
|
|
17
17
|
import { logger } from '@cardano-sdk/util-dev';
|
|
18
18
|
|
|
@@ -70,7 +70,7 @@ describe('SharedWallet/delegation', () => {
|
|
|
70
70
|
({
|
|
71
71
|
wallet: faucetWallet,
|
|
72
72
|
providers: { stakePoolProvider }
|
|
73
|
-
} = await getWallet({ env, logger, name: 'Sending Wallet'
|
|
73
|
+
} = await getWallet({ env, logger, name: 'Sending Wallet' }));
|
|
74
74
|
|
|
75
75
|
// Make sure the wallet has sufficient funds to run this test
|
|
76
76
|
await walletReady(faucetWallet, initialFunds);
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
|
|
3
|
-
set -euo pipefail
|
|
4
|
-
|
|
5
|
-
here="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
|
|
6
|
-
root="$(cd "$here/.." && pwd)"
|
|
7
|
-
|
|
8
|
-
cd "$root"
|
|
9
|
-
|
|
10
|
-
export PATH=$PWD/bin:$PATH
|
|
11
|
-
|
|
12
|
-
user=$(cat /run/secrets/postgres_user)
|
|
13
|
-
pass=$(cat /run/secrets/postgres_password)
|
|
14
|
-
db=$(cat /run/secrets/postgres_db)
|
|
15
|
-
|
|
16
|
-
queryResult=$(psql -d postgresql://"$user":"$pass"@"$POSTGRES_HOST":"$POSTGRES_PORT"/"$db" -c 'select epoch.no from epoch order by epoch.no DESC limit 1')
|
|
17
|
-
arr=(${queryResult//\\n/ })
|
|
18
|
-
epoch="${arr[2]}"
|
|
19
|
-
|
|
20
|
-
if [[ $epoch -lt 3 ]]; then
|
|
21
|
-
exit 9
|
|
22
|
-
fi
|
|
23
|
-
|
|
24
|
-
exit 0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|