Skip to content

Commit

Permalink
Chore: Add fee as param in SNS Stake neuron (#269)
Browse files Browse the repository at this point in the history
# Motivation

Expose the optional para fee of SNS transactions also when staking SNS
neuron.

# Changes

* Add "fee" in SnsStakeNeuronParams.

# Tests

* Add param in one test.
* Rewrite the description of some tests to make more concise what they
are testing.

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
lmuntaner and github-actions[bot] authored Jan 26, 2023
1 parent 269e253 commit 7bff237
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/sns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,9 @@ This is a convenient method that transfers the stake to the neuron subaccount an

⚠️ This feature is provided as it without warranty. It does not implement any additional checks of the validity of the payment flow - e.g. it does not handle refund nor retries claiming the neuron in case of errors.

| Method | Type |
| ------------- | ------------------------------------------------------------------------------------------- |
| `stakeNeuron` | `({ stakeE8s, source, controller, createdAt, }: SnsStakeNeuronParams) => Promise<NeuronId>` |
| Method | Type |
| ------------- | ------------------------------------------------------------------------------------------------ |
| `stakeNeuron` | `({ stakeE8s, source, controller, createdAt, fee, }: SnsStakeNeuronParams) => Promise<NeuronId>` |

##### :gear: increaseStakeNeuron

Expand Down
5 changes: 3 additions & 2 deletions packages/sns/src/sns.wrapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ describe("SnsWrapper", () => {

afterEach(() => jest.clearAllMocks());

it("should check balances with query call until one with 0 is found", async () => {
it("should check whether neuron exists with that account until one with no neuron is found", async () => {
mockCertifiedGovernanceCanister.queryNeuron
.mockResolvedValueOnce(neuronMock)
.mockResolvedValueOnce(neuronMock)
Expand All @@ -567,6 +567,7 @@ describe("SnsWrapper", () => {
stakeE8s,
source: mockSnsAccount,
controller: mockPrincipal,
fee: BigInt(10_000),
});

expect(
Expand All @@ -590,7 +591,7 @@ describe("SnsWrapper", () => {
).toBe(true);
});

it("should check with update when 0 is found and continue if that is not 0", async () => {
it("should check query neuron with update when one is found", async () => {
mockCertifiedGovernanceCanister.queryNeuron
.mockResolvedValueOnce(neuronMock)
.mockResolvedValueOnce(neuronMock)
Expand Down
2 changes: 2 additions & 0 deletions packages/sns/src/sns.wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export class SnsWrapper {
source,
controller,
createdAt,
fee,
}: SnsStakeNeuronParams): Promise<NeuronId> => {
this.assertCertified("stakeNeuron");
const { account: neuronAccount, index } = await this.nextNeuronAccount(
Expand All @@ -262,6 +263,7 @@ export class SnsWrapper {
from_subaccount: source.subaccount,
memo: bigIntToUint8Array(index),
created_at_time: createdAt,
fee,
});
return this.governance.claimNeuron({
memo: BigInt(index),
Expand Down
1 change: 1 addition & 0 deletions packages/sns/src/types/governance.params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface SnsStakeNeuronParams extends Omit<QueryParams, "certified"> {
controller: Principal;
// Same as createdAt from ledger's TransferParams
createdAt?: bigint;
fee?: bigint;
}

export interface SnsIncreaseStakeNeuronParams
Expand Down

0 comments on commit 7bff237

Please sign in to comment.