Skip to content

Commit

Permalink
chore(core-magistrate): more flexible entity types / sub-types + fees…
Browse files Browse the repository at this point in the history
… update (#3986)
  • Loading branch information
air1one authored Aug 28, 2020
1 parent 48e67e5 commit 06261f9
Show file tree
Hide file tree
Showing 41 changed files with 672 additions and 412 deletions.
58 changes: 49 additions & 9 deletions __tests__/functional/transaction-forging/entity-register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ describe("Transaction Forging - Entity registration", () => {
const registrations = [];
let nonce = Utils.BigNumber.make(2);
for (const { type, subType, name } of [
{ type: Enums.EntityType.Business, subType: Enums.EntitySubType.None, name: "bzness" },
{ type: Enums.EntityType.Delegate, subType: Enums.EntitySubType.None, name: "genesis_1" },
{ type: Enums.EntityType.Developer, subType: Enums.EntitySubType.None, name: "dvloper" },
{ type: Enums.EntityType.Plugin, subType: Enums.EntitySubType.PluginCore, name: "plgincore" },
{ type: Enums.EntityType.Plugin, subType: Enums.EntitySubType.PluginDesktop, name: "plgindskt" },
{ type: Enums.EntityType.Business, subType: 0, name: "bzness" },
{ type: Enums.EntityType.Delegate, subType: 1, name: "genesis_1" },
{ type: Enums.EntityType.Developer, subType: 6, name: "dvloper" },
{ type: Enums.EntityType.Plugin, subType: 255, name: "plgincore" },
{ type: Enums.EntityType.Plugin, subType: 134, name: "plgindskt" },
{ type: 255, subType: 134, name: "type255shouldwork" },
{ type: 174, subType: 33, name: "type174shouldwork" },
]) {
registrations.push(
TransactionFactory.entity({ type, subType, action: Enums.EntityAction.Register, data: { name } })
Expand Down Expand Up @@ -53,7 +55,7 @@ describe("Transaction Forging - Entity registration", () => {
// entity registration
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Bridgechain,
subType: Enums.EntitySubType.None,
subType: 0,
action: Enums.EntityAction.Register,
data: {
name: "plzacceptbridgechain",
Expand All @@ -72,7 +74,7 @@ describe("Transaction Forging - Entity registration", () => {
// entity registration
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Plugin,
subType: Enums.EntitySubType.PluginDesktop,
subType: 1,
action: Enums.EntityAction.Register,
data: {
name: "\u0008name",
Expand All @@ -86,6 +88,44 @@ describe("Transaction Forging - Entity registration", () => {
await expect(entityRegistration.id).not.toBeForged();
await expect(entityRegistration).not.entityRegistered();
});

it("should reject entity registration, because entity type is > 255 [Signed with 1 Passphrase]", async () => {
// entity registration
const entityRegistration = TransactionFactory.entity({
type: 256,
subType: 1,
action: Enums.EntityAction.Register,
data: {
name: "name256",
},
})
.withPassphrase(secrets[0])
.createOne();

await expect(entityRegistration).toBeRejected();
await support.snoozeForBlock(1);
await expect(entityRegistration.id).not.toBeForged();
await expect(entityRegistration).not.entityRegistered();
});

it("should reject entity registration, because entity sub type is > 255 [Signed with 1 Passphrase]", async () => {
// entity registration
const entityRegistration = TransactionFactory.entity({
type: 1,
subType: 256,
action: Enums.EntityAction.Register,
data: {
name: "namesubtype256",
},
})
.withPassphrase(secrets[0])
.createOne();

await expect(entityRegistration).toBeRejected();
await support.snoozeForBlock(1);
await expect(entityRegistration.id).not.toBeForged();
await expect(entityRegistration).not.entityRegistered();
});
});

describe("Signed with 2 Passphrases", () => {
Expand Down Expand Up @@ -115,7 +155,7 @@ describe("Transaction Forging - Entity registration", () => {
// Registering entity
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Business,
subType: Enums.EntitySubType.None,
subType: 0,
action: Enums.EntityAction.Register,
data: {
name: "my_bizbiz",
Expand Down Expand Up @@ -177,7 +217,7 @@ describe("Transaction Forging - Entity registration", () => {
// Registering entity
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Developer,
subType: Enums.EntitySubType.None,
subType: 0,
action: Enums.EntityAction.Register,
data: {
name: "iam_a_developer",
Expand Down
69 changes: 56 additions & 13 deletions __tests__/functional/transaction-forging/entity-resign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ beforeAll(async () => await support.setUp());
afterAll(async () => await support.tearDown());

describe("Transaction Forging - Entity resign", () => {
const staticFeeResign = 500000000;
const subType = 5; // subType is valid between 0 and 255
const type = 177; // type is valid between 0 and 255
describe("Signed with 1 Passphrase", () => {
it("should broadcast, accept and forge it [Signed with 1 Passphrase]", async () => {
for (let i = 0; i < 30; i++) {
Expand All @@ -18,8 +21,8 @@ describe("Transaction Forging - Entity resign", () => {

// Registering a desktop wallet plugin
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Plugin,
subType: Enums.EntitySubType.PluginDesktop,
type,
subType,
action: Enums.EntityAction.Register,
data: {
name: "my_plugin_for_desktop_wallet",
Expand All @@ -35,12 +38,13 @@ describe("Transaction Forging - Entity resign", () => {

// Resigning the entity
const entityResign = TransactionFactory.entity({
type: Enums.EntityType.Plugin,
subType: Enums.EntitySubType.PluginDesktop,
type,
subType,
action: Enums.EntityAction.Resign,
registrationId: entityRegistration.id,
data: {},
})
.withFee(staticFeeResign)
.withPassphrase(secrets[0])
.createOne();

Expand All @@ -50,11 +54,46 @@ describe("Transaction Forging - Entity resign", () => {
await expect(entityRegistration.id).entityResigned();
});

it("should reject entity resign, because of incorrect fee [Signed with 1 Passphrase]", async () => {
// entity registration
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Plugin,
subType,
action: Enums.EntityAction.Register,
data: {
name: "some_other_name",
},
})
.withPassphrase(secrets[0])
.createOne();

await expect(entityRegistration).toBeAccepted();
await support.snoozeForBlock(1);
await expect(entityRegistration.id).toBeForged();

// Trying to resign the desktop wallet plugin of secrets[0] wallet using secrets[1]
const entityResign = TransactionFactory.entity({
type: Enums.EntityType.Plugin,
subType,
action: Enums.EntityAction.Resign,
registrationId: entityRegistration.id,
data: {},
})
.withFee(5000000000) // this is an invalid fee - fee for register (50) instead of resign fee
.withPassphrase(secrets[1])
.createOne();

await expect(entityResign).toBeRejected();
await support.snoozeForBlock(1);
await expect(entityResign.id).not.toBeForged();
await expect(entityRegistration.id).not.entityResigned();
});

it("should reject entity resign, because associated register belongs to another wallet [Signed with 1 Passphrase]", async () => {
// entity registration
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Plugin,
subType: Enums.EntitySubType.PluginDesktop,
subType,
action: Enums.EntityAction.Register,
data: {
name: "another_name",
Expand All @@ -70,11 +109,12 @@ describe("Transaction Forging - Entity resign", () => {
// Trying to resign the desktop wallet plugin of secrets[0] wallet using secrets[1]
const entityResign = TransactionFactory.entity({
type: Enums.EntityType.Plugin,
subType: Enums.EntitySubType.PluginDesktop,
subType,
action: Enums.EntityAction.Resign,
registrationId: entityRegistration.id,
data: {},
})
.withFee(staticFeeResign)
.withPassphrase(secrets[1])
.createOne();

Expand All @@ -88,7 +128,7 @@ describe("Transaction Forging - Entity resign", () => {
// entity registration
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Plugin,
subType: Enums.EntitySubType.PluginDesktop,
subType,
action: Enums.EntityAction.Register,
data: {
name: "again_another_name",
Expand All @@ -102,14 +142,15 @@ describe("Transaction Forging - Entity resign", () => {
await expect(entityRegistration.id).toBeForged();
await expect(entityRegistration).entityRegistered();

// Trying to resign the desktop wallet plugin using PluginCore subtype
// Trying to resign with a different subType
const entityResign = TransactionFactory.entity({
type: Enums.EntityType.Plugin,
subType: Enums.EntitySubType.PluginCore,
subType: subType + 11,
action: Enums.EntityAction.Resign,
registrationId: entityRegistration.id,
data: {},
})
.withFee(staticFeeResign)
.withPassphrase(secrets[0])
.createOne();

Expand Down Expand Up @@ -147,7 +188,7 @@ describe("Transaction Forging - Entity resign", () => {
// Registering entity
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Business,
subType: Enums.EntitySubType.None,
subType,
action: Enums.EntityAction.Register,
data: {
name: "by_bizbiz",
Expand All @@ -164,11 +205,12 @@ describe("Transaction Forging - Entity resign", () => {
// Updating entity
const entityResign = TransactionFactory.entity({
type: Enums.EntityType.Business,
subType: Enums.EntitySubType.None,
subType,
action: Enums.EntityAction.Resign,
registrationId: entityRegistration.id,
data: {},
})
.withFee(staticFeeResign)
.withPassphrase(passphrase)
.withSecondPassphrase(secondPassphrase)
.createOne();
Expand Down Expand Up @@ -224,7 +266,7 @@ describe("Transaction Forging - Entity resign", () => {
// Registering entity
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Developer,
subType: Enums.EntitySubType.None,
subType,
action: Enums.EntityAction.Register,
data: {
name: "iam_a_developer",
Expand All @@ -241,11 +283,12 @@ describe("Transaction Forging - Entity resign", () => {
// Updating entity
const entityResign = TransactionFactory.entity({
type: Enums.EntityType.Developer,
subType: Enums.EntitySubType.None,
subType,
action: Enums.EntityAction.Resign,
registrationId: entityRegistration.id,
data: {},
})
.withFee(staticFeeResign)
.withSenderPublicKey(multiSigPublicKey)
.withPassphraseList(passphrases)
.createOne();
Expand Down
Loading

0 comments on commit 06261f9

Please sign in to comment.