-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #943 from ava-labs/fix/cap-tx-complexity
fix: cap tx complexity
- Loading branch information
Showing
10 changed files
with
137 additions
and
17 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
32 changes: 32 additions & 0 deletions
32
src/vms/pvm/etna-builder/spend-reducers/verifyGasUsage.test.ts
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,32 @@ | ||
import { describe, expect, test, vi } from 'vitest'; | ||
import { testContext } from '../../../../fixtures/context'; | ||
import { getInitialReducerState, getSpendHelper } from './fixtures/reducers'; | ||
import { verifyGasUsage } from './verifyGasUsage'; | ||
|
||
describe('verifyGasUsage', () => { | ||
test('returns original state if gas is under the threshold', () => { | ||
const initialState = getInitialReducerState(); | ||
const spendHelper = getSpendHelper(); | ||
const spy = vi.spyOn(spendHelper, 'verifyGasUsage'); | ||
|
||
const state = verifyGasUsage(initialState, spendHelper, testContext); | ||
|
||
expect(state).toBe(initialState); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('throws an error if gas is over the threshold', () => { | ||
const initialState = getInitialReducerState(); | ||
const spendHelper = getSpendHelper(); | ||
|
||
// Mock the verifyGasUsage method to throw an error | ||
// Testing for this function can be found in the spendHelper.test.ts file | ||
spendHelper.verifyGasUsage = vi.fn(() => { | ||
return new Error('Test error'); | ||
}); | ||
|
||
expect(() => | ||
verifyGasUsage(initialState, spendHelper, testContext), | ||
).toThrow('Test error'); | ||
}); | ||
}); |
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,16 @@ | ||
import type { SpendReducerFunction } from './types'; | ||
|
||
/** | ||
* Verify that gas usage is within limits. | ||
* | ||
* Calls the spendHelper's verifyGasUsage method. | ||
*/ | ||
export const verifyGasUsage: SpendReducerFunction = (state, spendHelper) => { | ||
const verifyError = spendHelper.verifyGasUsage(); | ||
|
||
if (verifyError) { | ||
throw verifyError; | ||
} | ||
|
||
return state; | ||
}; |
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