|
| 1 | +import "jest-extended"; |
| 2 | + |
| 3 | +import { Generators } from "@packages/core-test-framework/src"; |
| 4 | +import { TransactionType } from "@packages/crypto/src/enums"; |
| 5 | +import { configManager } from "@packages/crypto/src/managers"; |
| 6 | +import { Utils } from "@packages/crypto/src/transactions"; |
| 7 | +import { BuilderFactory } from "@packages/crypto/src/transactions/builders"; |
| 8 | +import { BlsPublicKeyRegistrationBuilder } from "@packages/crypto/src/transactions/builders/transactions/bls-public-key-registration"; |
| 9 | +import { Two } from "@packages/crypto/src/transactions/types"; |
| 10 | +import { BigNumber } from "@packages/crypto/src/utils"; |
| 11 | + |
| 12 | +let builder: BlsPublicKeyRegistrationBuilder; |
| 13 | + |
| 14 | +beforeEach(() => { |
| 15 | + // todo: completely wrap this into a function to hide the generation and setting of the config? |
| 16 | + const config = Generators.generateCryptoConfigRaw(); |
| 17 | + configManager.setConfig(config); |
| 18 | +}); |
| 19 | + |
| 20 | +describe("Bls Public Key Registration Transaction", () => { |
| 21 | + describe("verify", () => { |
| 22 | + beforeEach(() => { |
| 23 | + builder = BuilderFactory.blsPublicKeyRegistration(); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should be valid with a signature", () => { |
| 27 | + const actual = builder |
| 28 | + .blsPublicKeyAsset({ |
| 29 | + oldBlsPublicKey: "a".repeat(96), |
| 30 | + newBlsPublicKey: "b".repeat(96), |
| 31 | + }) |
| 32 | + .sign("dummy passphrase"); |
| 33 | + |
| 34 | + expect(actual.build().verified).toBeTrue(); |
| 35 | + expect(actual.verify()).toBeTrue(); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should be valid with a second signature", () => { |
| 39 | + const actual = builder |
| 40 | + .blsPublicKeyAsset({ |
| 41 | + oldBlsPublicKey: "a".repeat(96), |
| 42 | + newBlsPublicKey: "b".repeat(96), |
| 43 | + }) |
| 44 | + .sign("dummy passphrase") |
| 45 | + .secondSign("dummy passphrase"); |
| 46 | + |
| 47 | + expect(actual.build().verified).toBeTrue(); |
| 48 | + expect(actual.verify()).toBeTrue(); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + describe("properties", () => { |
| 53 | + beforeEach(() => { |
| 54 | + builder = BuilderFactory.blsPublicKeyRegistration(); |
| 55 | + }); |
| 56 | + |
| 57 | + it("should have its specific properties", () => { |
| 58 | + expect(builder).toHaveProperty("data.type", TransactionType.BlsPublicKeyRegistration); |
| 59 | + expect(builder).toHaveProperty("data.amount", BigNumber.ZERO); |
| 60 | + expect(builder).toHaveProperty("data.fee", Two.BlsPublicKeyRegistrationTransaction.staticFee()); |
| 61 | + expect(builder).toHaveProperty("data.recipientId", undefined); |
| 62 | + expect(builder).toHaveProperty("data.senderPublicKey", undefined); |
| 63 | + expect(builder).toHaveProperty("data.asset", {}); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + describe("blsPublicKeyAsset", () => { |
| 68 | + beforeEach(() => { |
| 69 | + builder = BuilderFactory.blsPublicKeyRegistration(); |
| 70 | + }); |
| 71 | + it("establishes the newBlsPublicKey and oldBlsPublicKey of the asset", () => { |
| 72 | + builder.blsPublicKeyAsset({ |
| 73 | + oldBlsPublicKey: "a".repeat(96), |
| 74 | + newBlsPublicKey: "b".repeat(96), |
| 75 | + }); |
| 76 | + expect(builder.data.asset.blsPublicKey.oldBlsPublicKey).toBe("a".repeat(96)); |
| 77 | + expect(builder.data.asset.blsPublicKey.newBlsPublicKey).toBe("b".repeat(96)); |
| 78 | + }); |
| 79 | + |
| 80 | + it("establishes the newBlsPublicKey of the asset", () => { |
| 81 | + builder.blsPublicKeyAsset({ |
| 82 | + newBlsPublicKey: "b".repeat(96), |
| 83 | + }); |
| 84 | + expect(builder.data.asset.blsPublicKey.oldBlsPublicKey).toBeUndefined(); |
| 85 | + expect(builder.data.asset.blsPublicKey.newBlsPublicKey).toBe("b".repeat(96)); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + describe("getStruct", () => { |
| 90 | + beforeEach(() => { |
| 91 | + builder = BuilderFactory.blsPublicKeyRegistration().blsPublicKeyAsset({ |
| 92 | + oldBlsPublicKey: "a".repeat(96), |
| 93 | + newBlsPublicKey: "b".repeat(96), |
| 94 | + }); |
| 95 | + }); |
| 96 | + |
| 97 | + it("should fail if the transaction is not signed", () => { |
| 98 | + expect(() => builder.getStruct()).toThrow(/transaction.*sign/); |
| 99 | + }); |
| 100 | + |
| 101 | + describe("when is signed", () => { |
| 102 | + beforeEach(() => { |
| 103 | + configManager.getMilestone().aip11 = false; |
| 104 | + |
| 105 | + builder.version(1).sign("any pass"); |
| 106 | + }); |
| 107 | + |
| 108 | + it("returns the id", () => { |
| 109 | + expect(builder.getStruct().id).toBe(Utils.getId(builder.data)); |
| 110 | + }); |
| 111 | + |
| 112 | + it("returns the signature", () => { |
| 113 | + expect(builder.getStruct().signature).toBe(builder.data.signature); |
| 114 | + }); |
| 115 | + |
| 116 | + it("returns the second signature", () => { |
| 117 | + expect(builder.getStruct().secondSignature).toBe(builder.data.secondSignature); |
| 118 | + }); |
| 119 | + |
| 120 | + it("returns the timestamp", () => { |
| 121 | + expect(builder.getStruct().timestamp).toBe(builder.data.timestamp); |
| 122 | + }); |
| 123 | + |
| 124 | + it("returns the transaction type", () => { |
| 125 | + expect(builder.getStruct().type).toBe(builder.data.type); |
| 126 | + }); |
| 127 | + |
| 128 | + it("returns the fee", () => { |
| 129 | + expect(builder.getStruct().fee).toBe(builder.data.fee); |
| 130 | + }); |
| 131 | + |
| 132 | + it("returns the sender public key", () => { |
| 133 | + expect(builder.getStruct().senderPublicKey).toBe(builder.data.senderPublicKey); |
| 134 | + }); |
| 135 | + |
| 136 | + it("returns the amount", () => { |
| 137 | + expect(builder.getStruct().amount).toBe(builder.data.amount); |
| 138 | + }); |
| 139 | + |
| 140 | + it("returns the recipient udnefined", () => { |
| 141 | + expect(builder.getStruct().recipientId).toBeUndefined(); |
| 142 | + }); |
| 143 | + |
| 144 | + it("returns the asset", () => { |
| 145 | + expect(builder.getStruct().asset).toBe(builder.data.asset); |
| 146 | + }); |
| 147 | + }); |
| 148 | + }); |
| 149 | +}); |
0 commit comments