This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) Adding origin for Apps Transactions (#576)
* Adding origin field when creates a TX * refactor: replace list of arg by object in getApprovalTransaction and getExecutionTransaction function * minor changes * Allow execute if threshold is 1 for the first tx - Related to issue #563 - `lastTx` is required due to #489 * - Normalizing logic between createTransaction and processTransaction - Moving shared function to a new file * Refactor `doesTxNeedApproval` back to the `isExecution`-related meaning * Rename function and variable names * Add tests for `getNewTxNonce` and `shouldExecuteTransaction` functions * Pass `safeInstance` instead of `safeAddress` to `getNewTxNonce` * Update Tests - remove mocked `getGnosisSafeInstanceAt` - pass `safeInstance` instead of `safeAddress` to `getNewTxNonce` Co-authored-by: Fernando <[email protected]>
- Loading branch information
1 parent
afccc34
commit c047f74
Showing
8 changed files
with
272 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { getNewTxNonce, shouldExecuteTransaction } from '~/routes/safe/store/actions/utils' | ||
|
||
describe('Store actions utils > getNewTxNonce', () => { | ||
it(`should return txNonce if it's a valid value`, async () => { | ||
// Given | ||
const txNonce = '45' | ||
const lastTx = { | ||
nonce: 44 | ||
} | ||
const safeInstance = { | ||
nonce: () => Promise.resolve({ | ||
toString: () => Promise.resolve('45') | ||
}) | ||
} | ||
|
||
// When | ||
const nonce = await getNewTxNonce(txNonce, lastTx, safeInstance) | ||
|
||
// Then | ||
expect(nonce).toBe('45') | ||
}) | ||
|
||
it(`should return lastTx.nonce + 1 if txNonce is not valid`, async () => { | ||
// Given | ||
const txNonce = '' | ||
const lastTx = { | ||
nonce: 44 | ||
} | ||
const safeInstance = { | ||
nonce: () => Promise.resolve({ | ||
toString: () => Promise.resolve('45') | ||
}) | ||
} | ||
|
||
// When | ||
const nonce = await getNewTxNonce(txNonce, lastTx, safeInstance) | ||
|
||
// Then | ||
expect(nonce).toBe('45') | ||
}) | ||
|
||
it(`should retrieve contract's instance nonce value, if txNonce and lastTx are not valid`, async () => { | ||
// Given | ||
const txNonce = '' | ||
const lastTx = null | ||
const safeInstance = { | ||
nonce: () => Promise.resolve({ | ||
toString: () => Promise.resolve('45') | ||
}) | ||
} | ||
|
||
// When | ||
const nonce = await getNewTxNonce(txNonce, lastTx, safeInstance) | ||
|
||
// Then | ||
expect(nonce).toBe('45') | ||
}) | ||
}) | ||
|
||
describe('Store actions utils > shouldExecuteTransaction', () => { | ||
it(`should return false if there's a previous tx pending to be executed`, async () => { | ||
// Given | ||
const safeInstance = { | ||
getThreshold: () => Promise.resolve({ | ||
toNumber: () => 1 | ||
}) | ||
} | ||
const nonce = '1' | ||
const lastTx = { | ||
isExecuted: false | ||
} | ||
|
||
// When | ||
const isExecution = await shouldExecuteTransaction(safeInstance, nonce, lastTx) | ||
|
||
// Then | ||
expect(isExecution).toBeFalsy() | ||
}) | ||
|
||
it(`should return false if threshold is greater than 1`, async () => { | ||
// Given | ||
const safeInstance = { | ||
getThreshold: () => Promise.resolve({ | ||
toNumber: () => 2 | ||
}) | ||
} | ||
const nonce = '1' | ||
const lastTx = { | ||
isExecuted: true | ||
} | ||
|
||
// When | ||
const isExecution = await shouldExecuteTransaction(safeInstance, nonce, lastTx) | ||
|
||
// Then | ||
expect(isExecution).toBeFalsy() | ||
}) | ||
|
||
it(`should return true is threshold is 1 and previous tx is executed`, async () => { | ||
// Given | ||
const safeInstance = { | ||
getThreshold: () => Promise.resolve({ | ||
toNumber: () => 1 | ||
}) | ||
} | ||
const nonce = '1' | ||
const lastTx = { | ||
isExecuted: true | ||
} | ||
|
||
// When | ||
const isExecution = await shouldExecuteTransaction(safeInstance, nonce, lastTx) | ||
|
||
// Then | ||
expect(isExecution).toBeTruthy() | ||
}) | ||
}) |
Oops, something went wrong.