Skip to content

Commit

Permalink
chore(magistrate): activate all entity types + re-allocate entity typ…
Browse files Browse the repository at this point in the history
…e enum (#4020)
  • Loading branch information
air1one committed Sep 11, 2020
1 parent 785680c commit 649aeac
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 63 deletions.
25 changes: 3 additions & 22 deletions __tests__/functional/transaction-forging/entity-register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("Transaction Forging - Entity registration", () => {
for (const { type, subType, name } of [
{ 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.Product, subType: 6, name: "prduct" },
{ type: Enums.EntityType.Plugin, subType: 255, name: "plgincore" },
{ type: Enums.EntityType.Plugin, subType: 134, name: "plgindskt" },
{ type: 255, subType: 134, name: "type255shouldwork" },
Expand Down Expand Up @@ -51,25 +51,6 @@ describe("Transaction Forging - Entity registration", () => {
}
});

it("should reject bridgechain entity registration, because it is deactivated [Signed with 1 Passphrase]", async () => {
// entity registration
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Bridgechain,
subType: 0,
action: Enums.EntityAction.Register,
data: {
name: "plzacceptbridgechain",
},
})
.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 name contains unicode control characters [Signed with 1 Passphrase]", async () => {
// entity registration
const entityRegistration = TransactionFactory.entity({
Expand Down Expand Up @@ -216,11 +197,11 @@ describe("Transaction Forging - Entity registration", () => {

// Registering entity
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType: 0,
action: Enums.EntityAction.Register,
data: {
name: "iam_a_developer",
name: "iam_a_module",
},
})
.withSenderPublicKey(multiSigPublicKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ describe("Transaction Forging - Entity resign", () => {

// Registering entity
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType,
action: Enums.EntityAction.Register,
data: {
name: "iam_a_developer",
name: "iam_a_module",
},
})
.withSenderPublicKey(multiSigPublicKey)
Expand All @@ -282,7 +282,7 @@ describe("Transaction Forging - Entity resign", () => {

// Updating entity
const entityResign = TransactionFactory.entity({
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType,
action: Enums.EntityAction.Resign,
registrationId: entityRegistration.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ describe("Transaction Forging - Entity update", () => {

// Registering entity
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType,
action: Enums.EntityAction.Register,
data: {
name: "iam_a_developer",
name: "iam_a_module",
},
})
.withSenderPublicKey(multiSigPublicKey)
Expand All @@ -297,7 +297,7 @@ describe("Transaction Forging - Entity update", () => {

// Updating entity
const entityUpdate = TransactionFactory.entity({
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType,
action: Enums.EntityAction.Update,
registrationId: entityRegistration.id,
Expand Down
4 changes: 2 additions & 2 deletions __tests__/integration/core-api/handlers/entities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { setUp, tearDown } from "../__support__/setup";
import { utils } from "../utils";

const entityRegistrationAsset: IEntityWallet = {
type: Enums.EntityType.Developer,
type: Enums.EntityType.Plugin,
subType: 0,
data: {
name: "iam_a_dev",
name: "iam_a_plugin",
ipfsData: "Qdm2345ousd462",
},
};
Expand Down
12 changes: 10 additions & 2 deletions __tests__/unit/core-magistrate/fixtures/entity/assets/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { IEntityAsset } from "@arkecosystem/core-magistrate-crypto/dist/interfac
import { EntityAction, EntityType } from "@arkecosystem/core-magistrate-crypto/src/enums";

// valid types already assigned (in enum EntityType) + other "custom" but valid types (in range 0-255)
const allTypes = [EntityType.Business, EntityType.Bridgechain, EntityType.Developer, EntityType.Plugin, 99, 255];
const allTypes = [
EntityType.Business,
EntityType.Product,
EntityType.Module,
EntityType.Delegate,
EntityType.Plugin,
99,
255,
];
const allSubTypes = [0, 3, 77, 255]; // a few valid subTypes containing min (0) and max (255)
const allActions = [EntityAction.Register, EntityAction.Update, EntityAction.Resign];
const registrationIds = [undefined, "c8b924ec44ac3341a110d440f630149e97c8c9c630dff5040466834096eba7f9"];
Expand All @@ -18,7 +26,7 @@ const specialDatas = [
// base asset properties we will use to generate all kind of {data} with it
const baseAssets = [
{
type: EntityType.Developer,
type: EntityType.Module,
subType: 0,
action: EntityAction.Update,
registrationId: "533384534cd561fc17f72be0bb57bf39961954ba0741f53c08e3f463ef19118c",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export const validRegisters: Interfaces.IEntityAsset[] = [
},
},
...validAssetData.map(data => ({
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType: 0,
action: Enums.EntityAction.Register,
data: {
name: "my_developer",
name: "my_module",
...data,
},
})),
Expand Down Expand Up @@ -77,11 +77,11 @@ export const invalidRegisters: Interfaces.IEntityAsset[] = [
},
},
...invalidAssetData.map(data => ({
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType: 0,
action: Enums.EntityAction.Update,
data: {
name: "my developer",
name: "my_module",
...data,
},
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ export const invalidResigns: Interfaces.IEntityAsset[] = [
data: {},
},
...invalidAssetData.map(data => ({
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType: 0,
action: Enums.EntityAction.Update,
data,
})),
...validAssetData.map(data => ({
// even "valid" data are invalid for resign as we allow no property in data
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType: 0,
action: Enums.EntityAction.Update,
data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { invalidAssetData, validAssetData } from "./utils";

export const validUpdates: Interfaces.IEntityAsset[] = [
{
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType: 1, // this should be valid for schema (only invalid for handler)
action: Enums.EntityAction.Update,
registrationId: "e77a1d1d080ebce113dd27e1cb0a242ec8600fb72cd62ace4e46148bee1d3acc",
Expand All @@ -12,7 +12,7 @@ export const validUpdates: Interfaces.IEntityAsset[] = [
},
},
...validAssetData.map(data => ({
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType: 0,
action: Enums.EntityAction.Update,
registrationId: "e77a1d1d080ebce113dd27e1cb0a242ec8600fb72cd62ace4e46148bee1d3acc",
Expand All @@ -22,7 +22,7 @@ export const validUpdates: Interfaces.IEntityAsset[] = [

export const invalidUpdates: Interfaces.IEntityAsset[] = [
{
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType: 0,
action: Enums.EntityAction.Update,
data: {
Expand Down Expand Up @@ -66,7 +66,7 @@ export const invalidUpdates: Interfaces.IEntityAsset[] = [
},
},
...invalidAssetData.map(data => ({
type: Enums.EntityType.Developer,
type: Enums.EntityType.Module,
subType: 0,
action: Enums.EntityAction.Update,
data,
Expand Down
6 changes: 3 additions & 3 deletions packages/core-magistrate-crypto/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export enum MagistrateTransactionStaticFees {
// Entity types can be any integer between 0-255 but this enum keeps track of what has been assigned already
export enum EntityType {
Business = 0,
Bridgechain = 1, // not used anymore but type is kept in enum
Developer = 2,
Plugin = 3,
Product = 1,
Plugin = 2,
Module = 3,
Delegate = 4,
}

Expand Down
6 changes: 0 additions & 6 deletions packages/core-magistrate-transactions/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ export class EntityWrongSubTypeError extends Errors.TransactionError {
}
}

export class EntityDeactivatedError extends Errors.TransactionError {
public constructor() {
super("Failed to apply transaction, because the entity type is deactivated.");
}
}

export class EntitySenderIsNotDelegateError extends Errors.TransactionError {
constructor() {
super("Failed to apply transaction, because entity sender wallet is not a delegate.");
Expand Down
12 changes: 0 additions & 12 deletions packages/core-magistrate-transactions/src/handlers/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Database, EventEmitter, State, TransactionPool } from "@arkecosystem/co
import {
EntityAlreadyRegisteredError,
EntityAlreadyResignedError,
EntityDeactivatedError,
EntityNameAlreadyRegisteredError,
EntityNameDoesNotMatchDelegateError,
EntityNotRegisteredError,
Expand Down Expand Up @@ -69,10 +68,6 @@ export class EntityTransactionHandler extends IHandlers.TransactionHandler {
return;
}

if (this.isDeactivatedEntity(transaction)) {
throw new EntityDeactivatedError();
}

const staticFee: Utils.BigNumber = this.getConstructor().staticFee({ data: transaction.data });
if (!transaction.data.fee.isEqualTo(staticFee)) {
throw new StaticFeeMismatchError(staticFee.toFixed());
Expand Down Expand Up @@ -288,11 +283,4 @@ export class EntityTransactionHandler extends IHandlers.TransactionHandler {

wallet.setAttribute("entities", entities);
}

private isDeactivatedEntity(transaction: Interfaces.ITransaction): boolean {
if (transaction.data.asset.type === Enums.EntityType.Bridgechain) {
return true;
}
return false;
}
}

0 comments on commit 649aeac

Please sign in to comment.