Skip to content

Commit

Permalink
feat(core): add allowTokenBurningFromPlugins() settings method
Browse files Browse the repository at this point in the history
BREAKING CHANGE: renamed `allowTokenBurn()` to `allowTokenBurning()` on `TransactionBuilderSettings`
  • Loading branch information
capt-nemo429 committed Dec 12, 2022
1 parent 8db2a70 commit 26824dd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/builder/transactionBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe("basic construction", () => {
expect(builder.settings.maxTokensPerChangeBox).toBe(MAX_TOKENS_PER_BOX);

builder.configure((settings) => {
settings.allowTokenBurn(true).setMaxTokensPerChangeBox(10);
settings.allowTokenBurning(true).setMaxTokensPerChangeBox(10);
});

expect(builder.settings.canBurnTokens).toBeTruthy();
Expand Down Expand Up @@ -999,7 +999,7 @@ describe("Token burning", () => {
})
)
.payFee(RECOMMENDED_MIN_FEE_VALUE)
.configure((settings) => settings.allowTokenBurn(true)) // explicitly allow token burning
.configure((settings) => settings.allowTokenBurning(true)) // explicitly allow token burning
.build();

expect(transaction.outputs).toHaveLength(2);
Expand Down Expand Up @@ -1054,7 +1054,7 @@ describe("Token burning", () => {
.from(inputs)
.to(new OutputBuilder(outputValue - 1000000n, a1.address)) // will try to burn 1000000n
.payFee(RECOMMENDED_MIN_FEE_VALUE)
.configure((settings) => settings.allowTokenBurn(true));
.configure((settings) => settings.allowTokenBurning(true));

expect(() => {
builder.build();
Expand Down
32 changes: 27 additions & 5 deletions packages/core/src/builder/transactionBuilderSettings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,38 @@ import { TransactionBuilderSettings } from "./transactionBuilderSettings";
describe("Transaction builder settings", () => {
it("Should hold defaults on constructing", () => {
const settings = new TransactionBuilderSettings();
expect(settings.canBurnTokens).toEqual(false);
expect(settings.maxTokensPerChangeBox).toEqual(MAX_TOKENS_PER_BOX);
expect(settings.canBurnTokens).toBe(false);
expect(settings.canBurnTokensFromPlugins).toBe(false);
expect(settings.maxTokensPerChangeBox).toBe(MAX_TOKENS_PER_BOX);
});

it("Should reflect changes", () => {
const settings = new TransactionBuilderSettings()
.allowTokenBurn(true)
.allowTokenBurning(true)
.allowTokenBurningFromPlugins(true)
.setMaxTokensPerChangeBox(50);

expect(settings.canBurnTokens).toEqual(true);
expect(settings.maxTokensPerChangeBox).toEqual(50);
expect(settings.canBurnTokens).toBe(true);
expect(settings.canBurnTokensFromPlugins).toBe(true);
expect(settings.maxTokensPerChangeBox).toBe(50);

settings.allowTokenBurning(false);

expect(settings.canBurnTokens).toBe(false);
expect(settings.canBurnTokensFromPlugins).toBe(true);
});

it("Should allow token burning from plugins if it's globally allowed", () => {
const settings = new TransactionBuilderSettings().allowTokenBurning(true);

expect(settings.canBurnTokens).toBe(true);
expect(settings.canBurnTokensFromPlugins).toBe(true);
});

it("Should allow token burning only from plugins context", () => {
const settings = new TransactionBuilderSettings().allowTokenBurningFromPlugins(true);

expect(settings.canBurnTokens).toBe(false);
expect(settings.canBurnTokensFromPlugins).toBe(true);
});
});
23 changes: 22 additions & 1 deletion packages/core/src/builder/transactionBuilderSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { MAX_TOKENS_PER_BOX } from "../models";
export class TransactionBuilderSettings {
private _maxDistinctTokensPerChangeBox: number;
private _allowTokenBurn: boolean;
private _allowTokenPluginFromPlugins: boolean;

constructor() {
this._maxDistinctTokensPerChangeBox = MAX_TOKENS_PER_BOX;
this._allowTokenBurn = false;
this._allowTokenPluginFromPlugins = false;
}

public get maxTokensPerChangeBox(): number {
Expand All @@ -17,15 +19,34 @@ export class TransactionBuilderSettings {
return this._allowTokenBurn;
}

public get canBurnTokensFromPlugins(): boolean {
return this.canBurnTokens || this._allowTokenPluginFromPlugins;
}

/**
* Define max number of distinct tokens per change box
*/
public setMaxTokensPerChangeBox(max: number): TransactionBuilderSettings {
this._maxDistinctTokensPerChangeBox = max;

return this;
}

public allowTokenBurn(allow: boolean): TransactionBuilderSettings {
/**
* Allows or denies token burning from all contexts
*/
public allowTokenBurning(allow: boolean): TransactionBuilderSettings {
this._allowTokenBurn = allow;

return this;
}

/**
* Allows or denies token burning **only** from plugins context.
*/
public allowTokenBurningFromPlugins(allow: boolean): TransactionBuilderSettings {
this._allowTokenPluginFromPlugins = allow;

return this;
}
}

0 comments on commit 26824dd

Please sign in to comment.