|
| 1 | +import { Application, Container, Contracts, Providers, Services } from "@arkecosystem/core-kernel"; |
| 2 | +import { Identifiers } from "@arkecosystem/core-kernel/src/ioc"; |
| 3 | +import { NullEventDispatcher } from "@arkecosystem/core-kernel/src/services/events/drivers/null"; |
| 4 | +import { Wallets } from "@arkecosystem/core-state"; |
| 5 | +import { StateStore } from "@arkecosystem/core-state/src/stores/state"; |
| 6 | +import { |
| 7 | + addressesIndexer, |
| 8 | + ipfsIndexer, |
| 9 | + locksIndexer, |
| 10 | + publicKeysIndexer, |
| 11 | + usernamesIndexer, |
| 12 | +} from "@arkecosystem/core-state/src/wallets/indexers/indexers"; |
| 13 | +import { Collator } from "@arkecosystem/core-transaction-pool/src"; |
| 14 | +import { DynamicFeeMatcher } from "@arkecosystem/core-transaction-pool/src/dynamic-fee-matcher"; |
| 15 | +import { ExpirationService } from "@arkecosystem/core-transaction-pool/src/expiration-service"; |
| 16 | +import { Query } from "@arkecosystem/core-transaction-pool/src/query"; |
| 17 | +import { SenderState } from "@arkecosystem/core-transaction-pool/src/sender-state"; |
| 18 | +import { One, Two } from "@arkecosystem/core-transactions/src/handlers"; |
| 19 | +import { TransactionHandlerProvider } from "@arkecosystem/core-transactions/src/handlers/handler-provider"; |
| 20 | +import { TransactionHandlerRegistry } from "@arkecosystem/core-transactions/src/handlers/handler-registry"; |
| 21 | +import { Identities, Utils } from "@arkecosystem/crypto"; |
| 22 | +import { Mempool } from "@arkecosystem/core-transaction-pool/src/mempool"; |
| 23 | + |
| 24 | +// eslint-disable-next-line jest/no-mocks-import |
| 25 | +import { blockRepository } from "../__mocks__/block-repository"; |
| 26 | +// eslint-disable-next-line jest/no-mocks-import |
| 27 | +import { transactionRepository } from "../__mocks__/transaction-repository"; |
| 28 | + |
| 29 | +const logger = { |
| 30 | + notice: jest.fn(), |
| 31 | + debug: jest.fn(), |
| 32 | + warning: jest.fn(), |
| 33 | +}; |
| 34 | + |
| 35 | +export const initApp = (): Application => { |
| 36 | + const app: Application = new Application(new Container.Container()); |
| 37 | + app.bind(Identifiers.ApplicationNamespace).toConstantValue("testnet"); |
| 38 | + |
| 39 | + app.bind(Identifiers.LogService).toConstantValue(logger); |
| 40 | + |
| 41 | + app.bind<Services.Attributes.AttributeSet>(Identifiers.WalletAttributes) |
| 42 | + .to(Services.Attributes.AttributeSet) |
| 43 | + .inSingletonScope(); |
| 44 | + |
| 45 | + app.bind<Contracts.State.WalletIndexerIndex>(Identifiers.WalletRepositoryIndexerIndex).toConstantValue({ |
| 46 | + name: Contracts.State.WalletIndexes.Addresses, |
| 47 | + indexer: addressesIndexer, |
| 48 | + }); |
| 49 | + |
| 50 | + app.bind<Contracts.State.WalletIndexerIndex>(Container.Identifiers.WalletRepositoryIndexerIndex).toConstantValue({ |
| 51 | + name: Contracts.State.WalletIndexes.PublicKeys, |
| 52 | + indexer: publicKeysIndexer, |
| 53 | + }); |
| 54 | + |
| 55 | + app.bind<Contracts.State.WalletIndexerIndex>(Container.Identifiers.WalletRepositoryIndexerIndex).toConstantValue({ |
| 56 | + name: Contracts.State.WalletIndexes.Usernames, |
| 57 | + indexer: usernamesIndexer, |
| 58 | + }); |
| 59 | + |
| 60 | + app.bind<Contracts.State.WalletIndexerIndex>(Container.Identifiers.WalletRepositoryIndexerIndex).toConstantValue({ |
| 61 | + name: Contracts.State.WalletIndexes.Ipfs, |
| 62 | + indexer: ipfsIndexer, |
| 63 | + }); |
| 64 | + |
| 65 | + app.bind<Contracts.State.WalletIndexerIndex>(Container.Identifiers.WalletRepositoryIndexerIndex).toConstantValue({ |
| 66 | + name: Contracts.State.WalletIndexes.Locks, |
| 67 | + indexer: locksIndexer, |
| 68 | + }); |
| 69 | + |
| 70 | + app.bind(Identifiers.WalletFactory).toFactory<Contracts.State.Wallet>( |
| 71 | + (context: Container.interfaces.Context) => (address: string) => |
| 72 | + new Wallets.Wallet( |
| 73 | + address, |
| 74 | + new Services.Attributes.AttributeMap( |
| 75 | + context.container.get<Services.Attributes.AttributeSet>(Identifiers.WalletAttributes), |
| 76 | + ), |
| 77 | + ), |
| 78 | + ); |
| 79 | + |
| 80 | + app.bind(Container.Identifiers.PluginConfiguration).to(Providers.PluginConfiguration).inSingletonScope(); |
| 81 | + |
| 82 | + app.get<Providers.PluginConfiguration>(Container.Identifiers.PluginConfiguration).set("maxTransactionAge", 500); |
| 83 | + app.get<Providers.PluginConfiguration>(Container.Identifiers.PluginConfiguration).set( |
| 84 | + "maxTransactionBytes", |
| 85 | + 2000000, |
| 86 | + ); |
| 87 | + app.get<Providers.PluginConfiguration>(Container.Identifiers.PluginConfiguration).set( |
| 88 | + "maxTransactionsPerSender", |
| 89 | + 300, |
| 90 | + ); |
| 91 | + |
| 92 | + app.bind(Container.Identifiers.StateStore).to(StateStore).inTransientScope(); |
| 93 | + |
| 94 | + app.bind(Identifiers.TransactionPoolMempool).to(Mempool).inSingletonScope(); |
| 95 | + |
| 96 | + app.bind(Identifiers.TransactionPoolQuery).to(Query).inSingletonScope(); |
| 97 | + |
| 98 | + app.bind(Container.Identifiers.TransactionPoolCollator).to(Collator); |
| 99 | + app.bind(Container.Identifiers.TransactionPoolDynamicFeeMatcher).to(DynamicFeeMatcher); |
| 100 | + app.bind(Container.Identifiers.TransactionPoolExpirationService).to(ExpirationService); |
| 101 | + |
| 102 | + app.bind(Container.Identifiers.TransactionPoolSenderState).to(SenderState); |
| 103 | + app.bind(Container.Identifiers.TransactionPoolSenderMempoolFactory).toAutoFactory( |
| 104 | + Container.Identifiers.TransactionPoolSenderState, |
| 105 | + ); |
| 106 | + |
| 107 | + app.bind(Identifiers.WalletRepository).to(Wallets.WalletRepository).inSingletonScope(); |
| 108 | + |
| 109 | + app.bind(Identifiers.EventDispatcherService).to(NullEventDispatcher).inSingletonScope(); |
| 110 | + |
| 111 | + app.bind(Identifiers.BlockRepository).toConstantValue(blockRepository); |
| 112 | + |
| 113 | + app.bind(Identifiers.TransactionRepository).toConstantValue(transactionRepository); |
| 114 | + |
| 115 | + app.bind(Identifiers.TransactionHandler).to(One.TransferTransactionHandler); |
| 116 | + app.bind(Identifiers.TransactionHandler).to(Two.TransferTransactionHandler); |
| 117 | + app.bind(Identifiers.TransactionHandler).to(One.SecondSignatureRegistrationTransactionHandler); |
| 118 | + app.bind(Identifiers.TransactionHandler).to(Two.SecondSignatureRegistrationTransactionHandler); |
| 119 | + app.bind(Identifiers.TransactionHandler).to(One.DelegateRegistrationTransactionHandler); |
| 120 | + app.bind(Identifiers.TransactionHandler).to(Two.DelegateRegistrationTransactionHandler); |
| 121 | + app.bind(Identifiers.TransactionHandler).to(One.VoteTransactionHandler); |
| 122 | + app.bind(Identifiers.TransactionHandler).to(Two.VoteTransactionHandler); |
| 123 | + app.bind(Identifiers.TransactionHandler).to(One.MultiSignatureRegistrationTransactionHandler); |
| 124 | + app.bind(Identifiers.TransactionHandler).to(Two.MultiSignatureRegistrationTransactionHandler); |
| 125 | + app.bind(Identifiers.TransactionHandler).to(Two.IpfsTransactionHandler); |
| 126 | + app.bind(Identifiers.TransactionHandler).to(Two.MultiPaymentTransactionHandler); |
| 127 | + app.bind(Identifiers.TransactionHandler).to(Two.DelegateResignationTransactionHandler); |
| 128 | + app.bind(Identifiers.TransactionHandler).to(Two.HtlcLockTransactionHandler); |
| 129 | + app.bind(Identifiers.TransactionHandler).to(Two.HtlcClaimTransactionHandler); |
| 130 | + app.bind(Identifiers.TransactionHandler).to(Two.HtlcRefundTransactionHandler); |
| 131 | + |
| 132 | + app.bind(Identifiers.TransactionHandlerProvider).to(TransactionHandlerProvider).inSingletonScope(); |
| 133 | + app.bind(Identifiers.TransactionHandlerRegistry).to(TransactionHandlerRegistry).inSingletonScope(); |
| 134 | + |
| 135 | + return app; |
| 136 | +}; |
| 137 | + |
| 138 | +export const buildWallet = (app: Application, passphrase: string): Contracts.State.Wallet => { |
| 139 | + const walletRepository = app.get<Wallets.WalletRepository>(Identifiers.WalletRepository); |
| 140 | + |
| 141 | + const wallet: Contracts.State.Wallet = walletRepository.createWallet(Identities.Address.fromPassphrase(passphrase)); |
| 142 | + wallet.address = Identities.Address.fromPassphrase(passphrase); |
| 143 | + wallet.publicKey = Identities.PublicKey.fromPassphrase(passphrase); |
| 144 | + wallet.balance = Utils.BigNumber.make(7527654310); |
| 145 | + |
| 146 | + return wallet; |
| 147 | +}; |
0 commit comments