|
| 1 | +/* |
| 2 | + * Copyright 2018 NEM |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { Account } from '../../src/model/account/Account'; |
| 18 | +import { NetworkType } from '../../src/model/network/NetworkType'; |
| 19 | +import { Deadline } from '../../src/model/transaction/Deadline'; |
| 20 | +import { IntegrationTestHelper } from './IntegrationTestHelper'; |
| 21 | +import { LinkAction } from '../../src/model/transaction/LinkAction'; |
| 22 | +import { AccountKeyLinkTransaction } from '../../src/model/transaction/AccountKeyLinkTransaction'; |
| 23 | +import { PersistentDelegationRequestTransaction } from '../../src/model/transaction/PersistentDelegationRequestTransaction'; |
| 24 | +import { VrfKeyLinkTransaction } from '../../src/model/transaction/VrfKeyLinkTransaction'; |
| 25 | +import { NodeKeyLinkTransaction } from '../../src/model/transaction/NodeKeyLinkTransaction'; |
| 26 | + |
| 27 | +describe('PersistentHarvesting', () => { |
| 28 | + const helper = new IntegrationTestHelper(); |
| 29 | + let account: Account; |
| 30 | + let generationHash: string; |
| 31 | + let networkType: NetworkType; |
| 32 | + let remoteAccount: Account; |
| 33 | + const vrfKeyPair = Account.createFromPrivateKey( |
| 34 | + '82798EA9A2D2D202AFCCC82C40A287780BCA3C7F7A2FD5B754832804C6BE1BAA', |
| 35 | + NetworkType.MIJIN_TEST, |
| 36 | + ); |
| 37 | + |
| 38 | + before(() => { |
| 39 | + return helper.start().then(() => { |
| 40 | + remoteAccount = Account.generateNewAccount(helper.networkType); |
| 41 | + console.log(remoteAccount.privateKey, remoteAccount.publicAccount); |
| 42 | + account = helper.harvestingAccount; |
| 43 | + generationHash = helper.generationHash; |
| 44 | + networkType = helper.networkType; |
| 45 | + }); |
| 46 | + }); |
| 47 | + before(() => { |
| 48 | + return helper.listener.open(); |
| 49 | + }); |
| 50 | + |
| 51 | + after(() => { |
| 52 | + helper.listener.close(); |
| 53 | + }); |
| 54 | + |
| 55 | + /** |
| 56 | + * ========================= |
| 57 | + * Setup test data |
| 58 | + * ========================= |
| 59 | + */ |
| 60 | + |
| 61 | + describe('AccountKeyLinkTransaction', () => { |
| 62 | + it('standalone', () => { |
| 63 | + const accountLinkTransaction = AccountKeyLinkTransaction.create( |
| 64 | + Deadline.create(), |
| 65 | + remoteAccount.publicKey, |
| 66 | + LinkAction.Link, |
| 67 | + networkType, |
| 68 | + helper.maxFee, |
| 69 | + ); |
| 70 | + const signedTransaction = accountLinkTransaction.signWith(account, generationHash); |
| 71 | + |
| 72 | + return helper.announce(signedTransaction); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + describe('VrfKeyLinkTransaction', () => { |
| 77 | + it('standalone', () => { |
| 78 | + const vrfKeyLinkTransaction = VrfKeyLinkTransaction.create( |
| 79 | + Deadline.create(), |
| 80 | + vrfKeyPair.publicKey, |
| 81 | + LinkAction.Link, |
| 82 | + networkType, |
| 83 | + helper.maxFee, |
| 84 | + ); |
| 85 | + const signedTransaction = vrfKeyLinkTransaction.signWith(account, generationHash); |
| 86 | + |
| 87 | + return helper.announce(signedTransaction); |
| 88 | + }); |
| 89 | + }); |
| 90 | + |
| 91 | + describe('NodeKeyLinkTransaction', () => { |
| 92 | + it('standalone', () => { |
| 93 | + const nodeKeyLinkTransaction = NodeKeyLinkTransaction.create( |
| 94 | + Deadline.create(), |
| 95 | + 'cfd84eca83508bbee954668e4aecca736caefa615367da76afe6985d695381db', |
| 96 | + LinkAction.Link, |
| 97 | + networkType, |
| 98 | + helper.maxFee, |
| 99 | + ); |
| 100 | + const signedTransaction = nodeKeyLinkTransaction.signWith(account, generationHash); |
| 101 | + |
| 102 | + return helper.announce(signedTransaction); |
| 103 | + }); |
| 104 | + }); |
| 105 | + /** |
| 106 | + * ========================= |
| 107 | + * Tests |
| 108 | + * ========================= |
| 109 | + */ |
| 110 | + |
| 111 | + describe('transactions', () => { |
| 112 | + it('should create delegated harvesting transaction', () => { |
| 113 | + const tx = PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction( |
| 114 | + Deadline.create(), |
| 115 | + remoteAccount.privateKey, |
| 116 | + vrfKeyPair.privateKey, |
| 117 | + 'cfd84eca83508bbee954668e4aecca736caefa615367da76afe6985d695381db', |
| 118 | + NetworkType.MIJIN_TEST, |
| 119 | + helper.maxFee, |
| 120 | + ); |
| 121 | + |
| 122 | + const signedTransaction = tx.signWith(account, generationHash); |
| 123 | + return helper.announce(signedTransaction); |
| 124 | + }); |
| 125 | + }); |
| 126 | +}); |
0 commit comments