Skip to content

Commit

Permalink
Fix: Dissolved neuron if dissolved in the past (#1672)
Browse files Browse the repository at this point in the history
# Motivation

User can't disburse sns neurons because data shows
"WhenDissolvedTimestampSeconds" state.

# Changes

* Check whether WhenDissolvedTimestampSeconds is in the past and set it
to Unlocked state.

# Tests

* Add test with new case.
  • Loading branch information
lmuntaner authored Dec 30, 2022
1 parent 629135d commit 48292e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion frontend/src/lib/utils/sns-neuron.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export const getSnsNeuronState = ({
: NeuronState.Locked;
}
if ("WhenDissolvedTimestampSeconds" in dissolveState) {
return NeuronState.Dissolving;
// In case `nowInSeconds` ever changes and doesn't return an integer we use Math.floor
return dissolveState.WhenDissolvedTimestampSeconds <
BigInt(Math.floor(nowInSeconds()))
? NeuronState.Dissolved
: NeuronState.Dissolving;
}
return NeuronState.Unspecified;
};
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/tests/lib/utils/sns-neuron.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ describe("sns-neuron utils", () => {
expect(getSnsNeuronState(neuron)).toEqual(NeuronState.Dissolved);
});

it("returns DISSOLVED if dissolve in the past", () => {
const neuron = createMockSnsNeuron({
id: [1, 2, 3, 4],
state: NeuronState.Dissolving,
});
const dissolveState = neuron.dissolve_state[0];
if ("WhenDissolvedTimestampSeconds" in dissolveState) {
dissolveState.WhenDissolvedTimestampSeconds = BigInt(
Math.floor(Date.now() / 1000 - 3600)
);
}
expect(getSnsNeuronState(neuron)).toEqual(NeuronState.Dissolved);
});

it("returns DISSOLVED when DissolveDelaySeconds=0", () => {
const neuron = createMockSnsNeuron({
id: [1, 2, 3, 4],
Expand Down

0 comments on commit 48292e9

Please sign in to comment.