@mainsail/test-factories 0.0.1-evm.44
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/LICENSE +623 -0
- package/README.md +19 -0
- package/distribution/factories/factories/block.d.ts +4 -0
- package/distribution/factories/factories/block.d.ts.map +1 -0
- package/distribution/factories/factories/block.js +143 -0
- package/distribution/factories/factories/block.js.map +1 -0
- package/distribution/factories/factories/generate-app.d.ts +3 -0
- package/distribution/factories/factories/generate-app.d.ts.map +1 -0
- package/distribution/factories/factories/generate-app.js +42 -0
- package/distribution/factories/factories/generate-app.js.map +1 -0
- package/distribution/factories/factories/identity.d.ts +4 -0
- package/distribution/factories/factories/identity.d.ts.map +1 -0
- package/distribution/factories/factories/identity.js +27 -0
- package/distribution/factories/factories/identity.js.map +1 -0
- package/distribution/factories/factories/index.d.ts +4 -0
- package/distribution/factories/factories/index.d.ts.map +1 -0
- package/distribution/factories/factories/index.js +4 -0
- package/distribution/factories/factories/index.js.map +1 -0
- package/distribution/factories/factories/transaction.d.ts +7 -0
- package/distribution/factories/factories/transaction.d.ts.map +1 -0
- package/distribution/factories/factories/transaction.js +188 -0
- package/distribution/factories/factories/transaction.js.map +1 -0
- package/distribution/factories/factory-builder.d.ts +8 -0
- package/distribution/factories/factory-builder.d.ts.map +1 -0
- package/distribution/factories/factory-builder.js +16 -0
- package/distribution/factories/factory-builder.js.map +1 -0
- package/distribution/factories/factory.d.ts +13 -0
- package/distribution/factories/factory.d.ts.map +1 -0
- package/distribution/factories/factory.js +102 -0
- package/distribution/factories/factory.js.map +1 -0
- package/distribution/factories/helpers.d.ts +4 -0
- package/distribution/factories/helpers.d.ts.map +1 -0
- package/distribution/factories/helpers.js +15 -0
- package/distribution/factories/helpers.js.map +1 -0
- package/distribution/factories/index.d.ts +5 -0
- package/distribution/factories/index.d.ts.map +1 -0
- package/distribution/factories/index.js +5 -0
- package/distribution/factories/index.js.map +1 -0
- package/distribution/factories/types.d.ts +57 -0
- package/distribution/factories/types.d.ts.map +1 -0
- package/distribution/factories/types.js +2 -0
- package/distribution/factories/types.js.map +1 -0
- package/distribution/index.d.ts +3 -0
- package/distribution/index.d.ts.map +1 -0
- package/distribution/index.js +3 -0
- package/distribution/index.js.map +1 -0
- package/distribution/internal/index.d.ts +2 -0
- package/distribution/internal/index.d.ts.map +1 -0
- package/distribution/internal/index.js +2 -0
- package/distribution/internal/index.js.map +1 -0
- package/distribution/internal/passphrases.json +53 -0
- package/distribution/internal/signer.d.ts +9 -0
- package/distribution/internal/signer.d.ts.map +1 -0
- package/distribution/internal/signer.js +47 -0
- package/distribution/internal/signer.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Identifiers } from "@mainsail/constants";
|
|
2
|
+
import { assert, BigNumber } from "@mainsail/utils";
|
|
3
|
+
import dayjs from "dayjs";
|
|
4
|
+
import secrets from "../../internal/passphrases.json" with { type: "json" };
|
|
5
|
+
import { Signer } from "../../internal/signer.js";
|
|
6
|
+
import { generateApp } from "./generate-app.js";
|
|
7
|
+
import { GAS_PRICE } from "./transaction.js";
|
|
8
|
+
export const registerBlockFactory = async (factory, config) => {
|
|
9
|
+
const app = await generateApp(config);
|
|
10
|
+
factory.set("Block", async ({ options }) => {
|
|
11
|
+
const previousBlock = options.getPreviousBlock
|
|
12
|
+
? options.getPreviousBlock()
|
|
13
|
+
: await app
|
|
14
|
+
.get(Identifiers.Cryptography.Configuration)
|
|
15
|
+
.get("genesisBlock.block");
|
|
16
|
+
const { reward } = app
|
|
17
|
+
.get(Identifiers.Cryptography.Configuration)
|
|
18
|
+
.getMilestone(previousBlock.number);
|
|
19
|
+
const transactions = options.transactions || [];
|
|
20
|
+
if (options.transactionsCount) {
|
|
21
|
+
const signer = new Signer(app.get(Identifiers.Cryptography.Configuration).all(), options.nonce ?? "0");
|
|
22
|
+
const genesisAddresses = (previousBlock.transactions ?? [])
|
|
23
|
+
.map((transaction) => transaction.to)
|
|
24
|
+
.filter((address) => !!address);
|
|
25
|
+
for (let index = 0; index < options.transactionsCount; index++) {
|
|
26
|
+
transactions.push(await signer.makeTransfer({
|
|
27
|
+
amount: ((options.amount || 2) + index).toString(),
|
|
28
|
+
gasPrice: options.fee || GAS_PRICE,
|
|
29
|
+
passphrase: secrets[0],
|
|
30
|
+
recipientId: genesisAddresses[Math.floor(Math.random() * genesisAddresses.length)],
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const totals = {
|
|
35
|
+
gasPrice: BigNumber.ZERO,
|
|
36
|
+
gasUsed: 0,
|
|
37
|
+
};
|
|
38
|
+
const payloadBuffers = [];
|
|
39
|
+
const transactionData = [];
|
|
40
|
+
let payloadSize = transactions.length * 4;
|
|
41
|
+
for (const transaction of transactions) {
|
|
42
|
+
assert.string(transaction.hash);
|
|
43
|
+
totals.gasPrice = totals.gasPrice.plus(transaction.gasPrice);
|
|
44
|
+
// TODO: calculate actual gas used
|
|
45
|
+
totals.gasUsed += transaction.gasLimit;
|
|
46
|
+
payloadBuffers.push(Buffer.from(transaction.hash, "hex"));
|
|
47
|
+
transactionData.push(transaction.toData());
|
|
48
|
+
payloadSize += transaction.serialized.length;
|
|
49
|
+
}
|
|
50
|
+
const passphrase = options.passphrase || secrets[0];
|
|
51
|
+
const commit = {
|
|
52
|
+
block: await app.get(Identifiers.Cryptography.Block.Factory).make({
|
|
53
|
+
fee: BigNumber.make(totals.gasPrice),
|
|
54
|
+
gasUsed: totals.gasUsed,
|
|
55
|
+
logsBloom: "0".repeat(512),
|
|
56
|
+
number: previousBlock.number + 1,
|
|
57
|
+
parentHash: previousBlock.hash,
|
|
58
|
+
payloadSize,
|
|
59
|
+
proposer: await app
|
|
60
|
+
.getTagged(Identifiers.Cryptography.Identity.Address.Factory, "type", "wallet")
|
|
61
|
+
.fromMnemonic(passphrase),
|
|
62
|
+
reward: BigNumber.make(options.reward || reward),
|
|
63
|
+
round: 0,
|
|
64
|
+
stateRoot: "0".repeat(64),
|
|
65
|
+
timestamp: options.timestamp || dayjs().valueOf(),
|
|
66
|
+
transactionsCount: transactions.length,
|
|
67
|
+
transactionsRoot: app
|
|
68
|
+
.get(Identifiers.Cryptography.Hash.Factory)
|
|
69
|
+
.sha256(payloadBuffers)
|
|
70
|
+
.toString("hex"),
|
|
71
|
+
version: 1,
|
|
72
|
+
}, transactions),
|
|
73
|
+
// TODO: dont hardcode
|
|
74
|
+
proof: {
|
|
75
|
+
blockId: "365dbc2f380b65737b439f98ce9ef0318b00d5bbdda57daabea8341f91ce39e7",
|
|
76
|
+
height: 1,
|
|
77
|
+
round: 1,
|
|
78
|
+
signature: "97a16d3e938a1bc6866701b946e703cfa502d57a226e540f270c16585405378e93086dfb3b32ab2039aa2c197177c66b0fec074df5bfac037efd3dc41d98d50455a69ff1934d503ef69dffa08429f75e5677efca4f2de36d46f8258635e32a95",
|
|
79
|
+
validators: [
|
|
80
|
+
true,
|
|
81
|
+
true,
|
|
82
|
+
true,
|
|
83
|
+
true,
|
|
84
|
+
true,
|
|
85
|
+
true,
|
|
86
|
+
true,
|
|
87
|
+
true,
|
|
88
|
+
true,
|
|
89
|
+
true,
|
|
90
|
+
true,
|
|
91
|
+
true,
|
|
92
|
+
true,
|
|
93
|
+
true,
|
|
94
|
+
true,
|
|
95
|
+
true,
|
|
96
|
+
true,
|
|
97
|
+
true,
|
|
98
|
+
true,
|
|
99
|
+
true,
|
|
100
|
+
true,
|
|
101
|
+
true,
|
|
102
|
+
true,
|
|
103
|
+
true,
|
|
104
|
+
true,
|
|
105
|
+
true,
|
|
106
|
+
true,
|
|
107
|
+
true,
|
|
108
|
+
true,
|
|
109
|
+
true,
|
|
110
|
+
true,
|
|
111
|
+
true,
|
|
112
|
+
true,
|
|
113
|
+
true,
|
|
114
|
+
true,
|
|
115
|
+
true,
|
|
116
|
+
true,
|
|
117
|
+
true,
|
|
118
|
+
true,
|
|
119
|
+
true,
|
|
120
|
+
true,
|
|
121
|
+
true,
|
|
122
|
+
true,
|
|
123
|
+
true,
|
|
124
|
+
true,
|
|
125
|
+
true,
|
|
126
|
+
true,
|
|
127
|
+
true,
|
|
128
|
+
true,
|
|
129
|
+
true,
|
|
130
|
+
true,
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
// const serializedCommit = "365dbc2f380b65737b439f98ce9ef0318b00d5bbdda57daabea8341f91ce39e7010000000100000097a16d3e938a1bc6866701b946e703cfa502d57a226e540f270c16585405378e93086dfb3b32ab2039aa2c197177c66b0fec074df5bfac037efd3dc41d98d50455a69ff1934d503ef69dffa08429f75e5677efca4f2de36d46f8258635e32a9533010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
|
|
135
|
+
return {
|
|
136
|
+
...commit,
|
|
137
|
+
serialized: (await app
|
|
138
|
+
.get(Identifiers.Cryptography.Commit.Serializer)
|
|
139
|
+
.serializeCommit(commit)).toString("hex"),
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../../../source/factories/factories/block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,OAAO,MAAM,iCAAiC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAc7C,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EACxC,OAAuB,EACvB,MAA6C,EAC7B,EAAE;IAClB,MAAM,GAAG,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;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;iBACJ;aACD;SACD,CAAC;QAEF,uZAAuZ;QAEvZ,OAAO;YACN,GAAG,MAAM;YACT,UAAU,EAAE,CACX,MAAM,GAAG;iBACP,GAAG,CAAoC,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC;iBAClF,eAAe,CAAC,MAAM,CAAC,CACzB,CAAC,QAAQ,CAAC,KAAK,CAAC;SACjB,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-app.d.ts","sourceRoot":"","sources":["../../../source/factories/factories/generate-app.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAmBrD,eAAO,MAAM,WAAW,GACvB,QAAQ,SAAS,CAAC,MAAM,CAAC,oBAAoB,KAC3C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CA0BtC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Identifiers } from "@mainsail/constants";
|
|
2
|
+
import { ServiceProvider as CoreCryptoAddressBase58 } from "@mainsail/crypto-address-base58";
|
|
3
|
+
import { ServiceProvider as CoreCryptoAddressKeccak256 } from "@mainsail/crypto-address-keccak256";
|
|
4
|
+
import { ServiceProvider as CoreCryptoBlock } from "@mainsail/crypto-block";
|
|
5
|
+
import { ServiceProvider as CoreCryptoCommit } from "@mainsail/crypto-commit";
|
|
6
|
+
import { Configuration } from "@mainsail/crypto-config";
|
|
7
|
+
import { ServiceProvider as CoreCryptoHashBcrypto } from "@mainsail/crypto-hash-bcrypto";
|
|
8
|
+
import { ServiceProvider as CoreCryptoKeyPairBls } from "@mainsail/crypto-key-pair-bls12-381";
|
|
9
|
+
import { ServiceProvider as CoreCryptoKeyPairEcdsa } from "@mainsail/crypto-key-pair-ecdsa";
|
|
10
|
+
import { ServiceProvider as CoreCryptoMessages } from "@mainsail/crypto-messages";
|
|
11
|
+
import { ServiceProvider as CoreCryptoSignatureBls } from "@mainsail/crypto-signature-bls12-381";
|
|
12
|
+
import { ServiceProvider as CoreCryptoSignatureEcdsa } from "@mainsail/crypto-signature-ecdsa";
|
|
13
|
+
import { ServiceProvider as CoreCryptoTransaction } from "@mainsail/crypto-transaction";
|
|
14
|
+
import { ServiceProvider as CoreCryptoValidation } from "@mainsail/crypto-validation";
|
|
15
|
+
import { ServiceProvider as CoreCryptoWif } from "@mainsail/crypto-wif";
|
|
16
|
+
import { Application } from "@mainsail/kernel";
|
|
17
|
+
import { ServiceProvider as CoreSerializer } from "@mainsail/serializer";
|
|
18
|
+
import { ServiceProvider as CoreValidation } from "@mainsail/validation";
|
|
19
|
+
export const generateApp = async (config) => {
|
|
20
|
+
const app = new Application();
|
|
21
|
+
app.bind(Identifiers.Services.EventDispatcher.Service).toConstantValue({});
|
|
22
|
+
app.bind(Identifiers.Services.Log.Service).toConstantValue({});
|
|
23
|
+
app.bind(Identifiers.Cryptography.Configuration).to(Configuration).inSingletonScope();
|
|
24
|
+
app.get(Identifiers.Cryptography.Configuration).setConfig(config);
|
|
25
|
+
await app.resolve(CoreValidation).register();
|
|
26
|
+
await app.resolve(CoreCryptoValidation).register();
|
|
27
|
+
await app.resolve(CoreCryptoAddressKeccak256).register();
|
|
28
|
+
await app.resolve(CoreCryptoAddressBase58).register();
|
|
29
|
+
await app.resolve(CoreCryptoKeyPairEcdsa).register();
|
|
30
|
+
await app.resolve(CoreCryptoSignatureEcdsa).register();
|
|
31
|
+
await app.resolve(CoreCryptoHashBcrypto).register();
|
|
32
|
+
await app.resolve(CoreCryptoSignatureBls).register();
|
|
33
|
+
await app.resolve(CoreCryptoKeyPairBls).register();
|
|
34
|
+
await app.resolve(CoreCryptoTransaction).register();
|
|
35
|
+
await app.resolve(CoreCryptoBlock).register();
|
|
36
|
+
await app.resolve(CoreCryptoMessages).register();
|
|
37
|
+
await app.resolve(CoreCryptoCommit).register();
|
|
38
|
+
await app.resolve(CoreSerializer).register();
|
|
39
|
+
await app.resolve(CoreCryptoWif).register();
|
|
40
|
+
return app;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=generate-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-app.js","sourceRoot":"","sources":["../../../source/factories/factories/generate-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,eAAe,IAAI,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,eAAe,IAAI,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AACnG,OAAO,EAAE,eAAe,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,eAAe,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,IAAI,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,EAAE,eAAe,IAAI,oBAAoB,EAAE,MAAM,qCAAqC,C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2
|
+
import type { FactoryBuilder } from "../factory-builder.js";
|
|
3
|
+
export declare const registerIdentityFactory: (factory: FactoryBuilder, config: Contracts.Crypto.NetworkConfigPartial) => Promise<void>;
|
|
4
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../source/factories/factories/identity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAS5D,eAAO,MAAM,uBAAuB,GACnC,SAAS,cAAc,EACvB,QAAQ,SAAS,CAAC,MAAM,CAAC,oBAAoB,KAC3C,OAAO,CAAC,IAAI,CA6Bd,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Identifiers } from "@mainsail/constants";
|
|
2
|
+
import { generateMnemonic } from "bip39";
|
|
3
|
+
import { generateApp } from "./generate-app.js";
|
|
4
|
+
export const registerIdentityFactory = async (factory, config) => {
|
|
5
|
+
const app = await generateApp(config);
|
|
6
|
+
factory.set("Identity", async ({ options }) => {
|
|
7
|
+
const passphrase = options.passphrase || generateMnemonic();
|
|
8
|
+
const keyType = options.keyType || "wallet";
|
|
9
|
+
const application = options.app || app;
|
|
10
|
+
const keys = await application
|
|
11
|
+
.getTagged(Identifiers.Cryptography.Identity.KeyPair.Factory, "type", keyType)
|
|
12
|
+
.fromMnemonic(passphrase);
|
|
13
|
+
return {
|
|
14
|
+
address: await application
|
|
15
|
+
.get(Identifiers.Cryptography.Identity.Address.Factory)
|
|
16
|
+
.fromMnemonic(passphrase),
|
|
17
|
+
keys,
|
|
18
|
+
passphrase,
|
|
19
|
+
privateKey: keys.privateKey,
|
|
20
|
+
publicKey: keys.publicKey,
|
|
21
|
+
wif: await application
|
|
22
|
+
.get(Identifiers.Cryptography.Identity.Wif.Factory)
|
|
23
|
+
.fromMnemonic(passphrase),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../../source/factories/factories/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAGzC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQhD,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAC3C,OAAuB,EACvB,MAA6C,EAC7B,EAAE;IAClB,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;IAEtC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,OAAO,EAAwB,EAAE,EAAE;QACnE,MAAM,UAAU,GAAW,OAAO,CAAC,UAAU,IAAI,gBAAgB,EAAE,CAAC;QACpE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC;QAC5C,MAAM,WAAW,GAAiC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC;QAErE,MAAM,IAAI,GAAG,MAAM,WAAW;aAC5B,SAAS,CACT,WAAW,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EACjD,MAAM,EACN,OAAO,CACP;aACA,YAAY,CAAC,UAAU,CAAC,CAAC;QAE3B,OAAO;YACN,OAAO,EAAE,MAAM,WAAW;iBACxB,GAAG,CAAkC,WAAW,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC;iBACvF,YAAY,CAAC,UAAU,CAAC;YAC1B,IAAI;YACJ,UAAU;YACV,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,GAAG,EAAE,MAAM,WAAW;iBACpB,GAAG,CAA8B,WAAW,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;iBAC/E,YAAY,CAAC,UAAU,CAAC;SAC1B,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/factories/factories/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/factories/factories/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Contracts } from "@mainsail/contracts";
|
|
2
|
+
import type { FactoryBuilder } from "../factory-builder.js";
|
|
3
|
+
export declare const GAS_PRICE: number;
|
|
4
|
+
export declare const registerTransferFactory: (factory: FactoryBuilder, app: Contracts.Kernel.Application) => void;
|
|
5
|
+
export declare const registerEvmCallFactory: (factory: FactoryBuilder, app: Contracts.Kernel.Application) => void;
|
|
6
|
+
export declare const registerTransactionFactory: (factory: FactoryBuilder, config: Contracts.Crypto.NetworkConfigPartial) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../source/factories/factories/transaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAKrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAoC5D,eAAO,MAAM,SAAS,QAAU,CAAC;AAEjC,eAAO,MAAM,uBAAuB,GAAI,SAAS,cAAc,EAAE,KAAK,SAAS,CAAC,MAAM,CAAC,WAAW,KAAG,IAuBpG,CAAC;AAgJF,eAAO,MAAM,sBAAsB,GAAI,SAAS,cAAc,EAAE,KAAK,SAAS,CAAC,MAAM,CAAC,WAAW,KAAG,IAcnG,CAAC;AAEF,eAAO,MAAM,0BAA0B,GACtC,SAAS,cAAc,EACvB,QAAQ,SAAS,CAAC,MAAM,CAAC,oBAAoB,KAC3C,OAAO,CAAC,IAAI,CAWd,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { Identifiers } from "@mainsail/constants";
|
|
2
|
+
import { TransactionBuilder } from "@mainsail/crypto-transaction";
|
|
3
|
+
import { BigNumber } from "@mainsail/utils";
|
|
4
|
+
import secrets from "../../internal/passphrases.json" with { type: "json" };
|
|
5
|
+
import { generateApp } from "./generate-app.js";
|
|
6
|
+
const AMOUNT = 1;
|
|
7
|
+
const sign = async ({ entity, options }) => entity.sign(options.passphrase || secrets[0]);
|
|
8
|
+
const multiSign = async ({ entity, options }) =>
|
|
9
|
+
// const passphrases: string[] = options.passphrases || [secrets[0], secrets[1], secrets[2]];
|
|
10
|
+
// for (const [index, passphrase] of passphrases.entries()) {
|
|
11
|
+
// await entity.multiSign(passphrase, index);
|
|
12
|
+
// }
|
|
13
|
+
entity;
|
|
14
|
+
const applyModifiers = (entity, options) => {
|
|
15
|
+
entity.gasPrice(options.gasPrice || GAS_PRICE);
|
|
16
|
+
if (options.nonce) {
|
|
17
|
+
entity.nonce(options.nonce);
|
|
18
|
+
}
|
|
19
|
+
if (options.recipientAddress) {
|
|
20
|
+
entity.recipientAddress(options.recipientAddress);
|
|
21
|
+
}
|
|
22
|
+
return entity;
|
|
23
|
+
};
|
|
24
|
+
export const GAS_PRICE = 5 * 1e9;
|
|
25
|
+
export const registerTransferFactory = (factory, app) => {
|
|
26
|
+
factory.set("Transfer", async ({ options }) => {
|
|
27
|
+
const transferBuilder = app.resolve(TransactionBuilder);
|
|
28
|
+
return applyModifiers(transferBuilder
|
|
29
|
+
.value(BigNumber.make(options.amount || AMOUNT).toFixed())
|
|
30
|
+
.recipientAddress(options.recipientAddress ||
|
|
31
|
+
(await app
|
|
32
|
+
.get(Identifiers.Cryptography.Identity.Address.Factory)
|
|
33
|
+
.fromMnemonic(secrets[0]))), options);
|
|
34
|
+
});
|
|
35
|
+
factory.get("Transfer");
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
factory.get("Transfer").state("sign", sign);
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
factory.get("Transfer").state("multiSign", multiSign);
|
|
40
|
+
};
|
|
41
|
+
// export const registerValidatorRegistrationFactory = (
|
|
42
|
+
// factory: FactoryBuilder,
|
|
43
|
+
// app: Contracts.Kernel.Application,
|
|
44
|
+
// ): void => {
|
|
45
|
+
// factory.set("ValidatorRegistration", async ({ options }: { options: ValidatorRegistrationOptions }) =>
|
|
46
|
+
// applyModifiers(
|
|
47
|
+
// app.resolve(ValidatorRegistrationBuilder).publicKeyAsset(options.publicKey || "a".repeat(96)),
|
|
48
|
+
// options,
|
|
49
|
+
// ),
|
|
50
|
+
// );
|
|
51
|
+
// // @ts-ignore
|
|
52
|
+
// factory.get("ValidatorRegistration").state("sign", sign);
|
|
53
|
+
// };
|
|
54
|
+
// export const registerValidatorResignationFactory = (
|
|
55
|
+
// factory: FactoryBuilder,
|
|
56
|
+
// app: Contracts.Kernel.Application,
|
|
57
|
+
// ): void => {
|
|
58
|
+
// factory.set("ValidatorResignation", async ({ options }: { options: ValidatorResignationOptions }) =>
|
|
59
|
+
// applyModifiers(app.resolve(ValidatorResignationBuilder), options),
|
|
60
|
+
// );
|
|
61
|
+
// // @ts-ignore
|
|
62
|
+
// factory.get("ValidatorResignation").state("sign", sign);
|
|
63
|
+
// };
|
|
64
|
+
// export const registerVoteFactory = (factory: FactoryBuilder, app: Contracts.Kernel.Application): void => {
|
|
65
|
+
// factory.set("Vote", async ({ options }: { options: VoteOptions }) =>
|
|
66
|
+
// applyModifiers(
|
|
67
|
+
// app
|
|
68
|
+
// .resolve(VoteBuilder)
|
|
69
|
+
// .votesAsset([
|
|
70
|
+
// options.publicKey ||
|
|
71
|
+
// (await app
|
|
72
|
+
// .getTagged<Contracts.Crypto.PublicKeyFactory>(
|
|
73
|
+
// Identifiers.Cryptography.Identity.PublicKey.Factory,
|
|
74
|
+
// "type",
|
|
75
|
+
// "wallet",
|
|
76
|
+
// )
|
|
77
|
+
// .fromMnemonic(secrets[1])),
|
|
78
|
+
// ]),
|
|
79
|
+
// options,
|
|
80
|
+
// ),
|
|
81
|
+
// );
|
|
82
|
+
// // @ts-ignore
|
|
83
|
+
// factory.get("Vote").state("sign", sign);
|
|
84
|
+
// // @ts-ignore
|
|
85
|
+
// factory.get("Vote").state("multiSign", multiSign);
|
|
86
|
+
// };
|
|
87
|
+
// export const registerUnvoteFactory = (factory: FactoryBuilder, app: Contracts.Kernel.Application): void => {
|
|
88
|
+
// factory.set("Unvote", async ({ options }: { options: VoteOptions }) =>
|
|
89
|
+
// applyModifiers(
|
|
90
|
+
// app
|
|
91
|
+
// .resolve(VoteBuilder)
|
|
92
|
+
// .unvotesAsset([
|
|
93
|
+
// options.publicKey ||
|
|
94
|
+
// (await app
|
|
95
|
+
// .getTagged<Contracts.Crypto.PublicKeyFactory>(
|
|
96
|
+
// Identifiers.Cryptography.Identity.PublicKey.Factory,
|
|
97
|
+
// "type",
|
|
98
|
+
// "wallet",
|
|
99
|
+
// )
|
|
100
|
+
// .fromMnemonic(secrets[1])),
|
|
101
|
+
// ]),
|
|
102
|
+
// options,
|
|
103
|
+
// ),
|
|
104
|
+
// );
|
|
105
|
+
// // @ts-ignore
|
|
106
|
+
// factory.get("Unvote").state("sign", sign);
|
|
107
|
+
// // @ts-ignore
|
|
108
|
+
// factory.get("Unvote").state("multiSign", multiSign);
|
|
109
|
+
// };
|
|
110
|
+
// export const registerMultiSignature = (factory: FactoryBuilder, app: Contracts.Kernel.Application): void => {
|
|
111
|
+
// factory.set("MultiSignature", async ({ options }: { options: MultiSignatureOptions }) => {
|
|
112
|
+
// const publicKeyFactory = app.getTagged<Contracts.Crypto.PublicKeyFactory>(
|
|
113
|
+
// Identifiers.Cryptography.Identity.PublicKey.Factory,
|
|
114
|
+
// "type",
|
|
115
|
+
// "wallet",
|
|
116
|
+
// );
|
|
117
|
+
// const publicKeys: string[] = options.publicKeys || [
|
|
118
|
+
// await publicKeyFactory.fromMnemonic(secrets[0]),
|
|
119
|
+
// await publicKeyFactory.fromMnemonic(secrets[1]),
|
|
120
|
+
// await publicKeyFactory.fromMnemonic(secrets[2]),
|
|
121
|
+
// ];
|
|
122
|
+
// return applyModifiers(
|
|
123
|
+
// app
|
|
124
|
+
// .resolve(MultiSignatureBuilder)
|
|
125
|
+
// .multiSignatureAsset({
|
|
126
|
+
// min: options.min || 2,
|
|
127
|
+
// publicKeys,
|
|
128
|
+
// })
|
|
129
|
+
// .senderPublicKey(publicKeys[0]),
|
|
130
|
+
// options,
|
|
131
|
+
// );
|
|
132
|
+
// });
|
|
133
|
+
// // @ts-ignore
|
|
134
|
+
// factory.get("MultiSignature").state("sign", sign);
|
|
135
|
+
// // @ts-ignore
|
|
136
|
+
// factory.get("MultiSignature").state("multiSign", multiSign);
|
|
137
|
+
// };
|
|
138
|
+
// export const registerMultiPaymentFactory = (factory: FactoryBuilder, app: Contracts.Kernel.Application) => {
|
|
139
|
+
// factory.set("MultiPayment", async ({ options }: { options: MultiPaymentOptions }) => {
|
|
140
|
+
// const builder = app.resolve(MultiPaymentBuilder);
|
|
141
|
+
// const payments = options.payments || [
|
|
142
|
+
// {
|
|
143
|
+
// amount: AMOUNT.toString(),
|
|
144
|
+
// recipientId: await app
|
|
145
|
+
// .get<Contracts.Crypto.AddressFactory>(Identifiers.Cryptography.Identity.Address.Factory)
|
|
146
|
+
// .fromMnemonic(secrets[0]),
|
|
147
|
+
// },
|
|
148
|
+
// {
|
|
149
|
+
// amount: AMOUNT.toString(),
|
|
150
|
+
// recipientId: await app
|
|
151
|
+
// .get<Contracts.Crypto.AddressFactory>(Identifiers.Cryptography.Identity.Address.Factory)
|
|
152
|
+
// .fromMnemonic(secrets[1]),
|
|
153
|
+
// },
|
|
154
|
+
// ];
|
|
155
|
+
// for (const payment of payments) {
|
|
156
|
+
// builder.addPayment(payment.recipientId, payment.amount);
|
|
157
|
+
// }
|
|
158
|
+
// applyModifiers(builder, options);
|
|
159
|
+
// return builder;
|
|
160
|
+
// });
|
|
161
|
+
// // @ts-ignore
|
|
162
|
+
// factory.get("MultiPayment").state("sign", sign);
|
|
163
|
+
// // @ts-ignore
|
|
164
|
+
// factory.get("MultiPayment").state("multiSign", multiSign);
|
|
165
|
+
// };
|
|
166
|
+
export const registerEvmCallFactory = (factory, app) => {
|
|
167
|
+
factory.set("EvmCall", async ({ options }) => {
|
|
168
|
+
const builder = app.resolve(TransactionBuilder);
|
|
169
|
+
builder.payload(options.evmCall?.payload ?? "");
|
|
170
|
+
builder.gasLimit(options.evmCall?.gasLimit ?? 21_000);
|
|
171
|
+
applyModifiers(builder, options);
|
|
172
|
+
return builder;
|
|
173
|
+
});
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
factory.get("EvmCall").state("sign", sign);
|
|
176
|
+
};
|
|
177
|
+
export const registerTransactionFactory = async (factory, config) => {
|
|
178
|
+
const app = await generateApp(config);
|
|
179
|
+
registerTransferFactory(factory, app);
|
|
180
|
+
// registerValidatorRegistrationFactory(factory, app);
|
|
181
|
+
// registerValidatorResignationFactory(factory, app);
|
|
182
|
+
// registerVoteFactory(factory, app);
|
|
183
|
+
// registerUnvoteFactory(factory, app);
|
|
184
|
+
// registerMultiSignature(factory, app);
|
|
185
|
+
// registerMultiPaymentFactory(factory, app);
|
|
186
|
+
registerEvmCallFactory(factory, app);
|
|
187
|
+
};
|
|
188
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../source/factories/factories/transaction.ts"],"names":[],"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D;AACpD,iBAAiB;AACjB,8DAA8D;AAC9D,KAAK;AAEL,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAAuB,EAAE,GAAiC,EAAQ,EAAE;IAC1G,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,OAAO,EAA+B,EAAE,EAAE;QACzE,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAEhD,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;QAChD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,IAAI,MAAM,CAAC,CAAC;QAEtD,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAEjC,OAAO,OAAO,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,aAAa;IACb,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,EAC9C,OAAuB,EACvB,MAA6C,EAC7B,EAAE;IAClB,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;IAEtC,uBAAuB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACtC,sDAAsD;IACtD,qDAAqD;IACrD,qCAAqC;IACrC,uCAAuC;IACvC,wCAAwC;IACxC,6CAA6C;IAC7C,sBAAsB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACtC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Factory } from "./factory.js";
|
|
2
|
+
import type { FactoryFunction } from "./types.js";
|
|
3
|
+
export declare class FactoryBuilder {
|
|
4
|
+
#private;
|
|
5
|
+
get<T>(factory: string): Factory<T>;
|
|
6
|
+
set(factory: string, function_: FactoryFunction): boolean;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=factory-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory-builder.d.ts","sourceRoot":"","sources":["../../source/factories/factory-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,qBAAa,cAAc;;IAGnB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAMnC,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,GAAG,OAAO;CAQhE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { strictEqual } from "assert";
|
|
2
|
+
import { Factory } from "./factory.js";
|
|
3
|
+
export class FactoryBuilder {
|
|
4
|
+
#factories = new Map();
|
|
5
|
+
get(factory) {
|
|
6
|
+
strictEqual(this.#factories.has(factory), true, `The [${factory}] factory is unknown.`);
|
|
7
|
+
return this.#factories.get(factory);
|
|
8
|
+
}
|
|
9
|
+
set(factory, function_) {
|
|
10
|
+
const instance = new Factory();
|
|
11
|
+
instance.state("default", function_);
|
|
12
|
+
this.#factories.set(factory, instance);
|
|
13
|
+
return this.#factories.has(factory);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=factory-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory-builder.js","sourceRoot":"","sources":["../../source/factories/factory-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,MAAM,OAAO,cAAc;IACjB,UAAU,GAAkC,IAAI,GAAG,EAA4B,CAAC;IAElF,GAAG,CAAI,OAAe;QAC5B,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,OAAO,uBAAuB,CAAC,CAAC;QAExF,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAgB,CAAC;IACpD,CAAC;IAEM,GAAG,CAAC,OAAe,EAAE,SAA0B;QACrD,MAAM,QAAQ,GAAqB,IAAI,OAAO,EAAE,CAAC;QACjD,QAAQ,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAErC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAEvC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FactoryFunction, FactoryFunctionOptions, HookFunction } from "./types.js";
|
|
2
|
+
export declare class Factory<T> {
|
|
3
|
+
#private;
|
|
4
|
+
state(state: string, function_: FactoryFunction): boolean;
|
|
5
|
+
afterMaking(function_: HookFunction): void;
|
|
6
|
+
afterMakingState(state: string, function_: HookFunction): void;
|
|
7
|
+
withStates(...states: string[]): this;
|
|
8
|
+
withAttributes(attributes: object): this;
|
|
9
|
+
withOptions(options: FactoryFunctionOptions): this;
|
|
10
|
+
make(resetModifiers?: boolean): Promise<T>;
|
|
11
|
+
makeMany(count: number): Promise<T[]>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../source/factories/factory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAExF,qBAAa,OAAO,CAAC,CAAC;;IAed,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,GAAG,OAAO;IAMzD,WAAW,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;IAI1C,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,GAAG,IAAI;IAM9D,UAAU,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI;IAUrC,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAMxC,WAAW,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI;IAM5C,IAAI,CAAC,cAAc,GAAE,OAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IA2ChD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;CAgDlD"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { assert } from "@mainsail/utils";
|
|
2
|
+
import { strictEqual } from "assert";
|
|
3
|
+
export class Factory {
|
|
4
|
+
#states = new Map();
|
|
5
|
+
#hooks = new Map();
|
|
6
|
+
#modifiers = {
|
|
7
|
+
attributes: {},
|
|
8
|
+
options: {},
|
|
9
|
+
states: new Set(["default"]),
|
|
10
|
+
};
|
|
11
|
+
state(state, function_) {
|
|
12
|
+
this.#states.set(state, function_);
|
|
13
|
+
return this.#states.has(state);
|
|
14
|
+
}
|
|
15
|
+
afterMaking(function_) {
|
|
16
|
+
this.afterMakingState("default", function_);
|
|
17
|
+
}
|
|
18
|
+
afterMakingState(state, function_) {
|
|
19
|
+
this.#assertKnownState(state);
|
|
20
|
+
this.#registerHook(state, function_);
|
|
21
|
+
}
|
|
22
|
+
withStates(...states) {
|
|
23
|
+
for (const state of states) {
|
|
24
|
+
this.#assertKnownState(state);
|
|
25
|
+
this.#modifiers.states.add(state);
|
|
26
|
+
}
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
withAttributes(attributes) {
|
|
30
|
+
this.#modifiers.attributes = attributes;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
withOptions(options) {
|
|
34
|
+
this.#modifiers.options = options;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
async make(resetModifiers = true) {
|
|
38
|
+
const states = [...this.#modifiers.states.values()];
|
|
39
|
+
const initialState = states.shift();
|
|
40
|
+
assert.string(initialState);
|
|
41
|
+
const function_ = this.#states.get(initialState);
|
|
42
|
+
assert.defined(function_);
|
|
43
|
+
let result = await function_({
|
|
44
|
+
entity: undefined,
|
|
45
|
+
options: this.#modifiers.options,
|
|
46
|
+
});
|
|
47
|
+
this.#applyHooks(initialState, result);
|
|
48
|
+
// We apply all states in order of insertion to guarantee consistency.
|
|
49
|
+
for (const state of states) {
|
|
50
|
+
const function_ = this.#states.get(state);
|
|
51
|
+
assert.defined(function_);
|
|
52
|
+
result = await function_({
|
|
53
|
+
entity: result,
|
|
54
|
+
options: this.#modifiers.options,
|
|
55
|
+
});
|
|
56
|
+
// We apply all hooks in order of insertion to guarantee consistency.
|
|
57
|
+
this.#applyHooks(state, result);
|
|
58
|
+
}
|
|
59
|
+
for (const [key, value] of Object.entries(this.#modifiers.attributes)) {
|
|
60
|
+
result[key] = value;
|
|
61
|
+
}
|
|
62
|
+
if (resetModifiers) {
|
|
63
|
+
this.#resetModifiers();
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
async makeMany(count) {
|
|
68
|
+
const entities = [];
|
|
69
|
+
for (let index = 0; index < count; index++) {
|
|
70
|
+
entities.push(await this.make(false));
|
|
71
|
+
}
|
|
72
|
+
this.#resetModifiers();
|
|
73
|
+
return entities;
|
|
74
|
+
}
|
|
75
|
+
#registerHook(state, function_) {
|
|
76
|
+
if (!this.#hooks.has(state)) {
|
|
77
|
+
this.#hooks.set(state, new Set());
|
|
78
|
+
}
|
|
79
|
+
const hooks = this.#hooks.get(state);
|
|
80
|
+
assert.defined(hooks);
|
|
81
|
+
hooks.add(function_);
|
|
82
|
+
this.#hooks.set(state, hooks);
|
|
83
|
+
}
|
|
84
|
+
#assertKnownState(state) {
|
|
85
|
+
strictEqual(this.#states.has(state), true, `The [${state}] state is unknown.`);
|
|
86
|
+
}
|
|
87
|
+
#applyHooks(state, value) {
|
|
88
|
+
const hooks = this.#hooks.get(state);
|
|
89
|
+
if (hooks) {
|
|
90
|
+
for (const hook of hooks) {
|
|
91
|
+
hook({ entity: value, options: {} }); // @TODO support hook options?
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
#resetModifiers() {
|
|
96
|
+
this.#modifiers.states.clear();
|
|
97
|
+
this.#modifiers.states.add("default");
|
|
98
|
+
this.#modifiers.options = {};
|
|
99
|
+
this.#modifiers.attributes = {};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=factory.js.map
|