-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat-split-db
- Loading branch information
Showing
30 changed files
with
1,251 additions
and
697 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,6 @@ | |
margin-left: 4px; | ||
|
||
path { | ||
fill: #ffffff; | ||
fill: var(--main-text-color); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -20,5 +20,6 @@ | |
color: #999; | ||
font-size: 12px; | ||
margin-left: 4px; | ||
white-space: nowrap; | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
packages/neuron-ui/src/tests/validators/capacity/fixtures.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,20 @@ | ||
import { ErrorCode } from 'utils/enums' | ||
|
||
export default { | ||
'Should throw an error when address is not a string': { | ||
params: { | ||
address: 'ckb1qrgqep8saj8agswr30pls73hra28ry8jlnlc3ejzh3dl2ju7xxpjxqgqqy28n5m69va267nv0wvsudngtxz8t9jwss3xkhpk', | ||
amount: '62', | ||
unit: 'ckb', | ||
}, | ||
exception: ErrorCode.CapacityTooSmall, | ||
}, | ||
'Should throw an error when address is required but not provided': { | ||
params: { | ||
address: 'ckb1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq2n0egquval9ljqm2ga6t9509kwcex5ejq3hy6dk', | ||
amount: '62', | ||
unit: 'ckb', | ||
}, | ||
exception: null, | ||
}, | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/neuron-ui/src/tests/validators/capacity/index.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,25 @@ | ||
import { describe, test, expect } from '@jest/globals' | ||
import { isErrorWithI18n } from 'exceptions' | ||
import { validateCapacity } from 'utils/validators' | ||
import fixtures from './fixtures' | ||
|
||
const fixtureTable: Fixture.Validator<typeof validateCapacity>[] = Object.entries(fixtures).map( | ||
([title, { params, exception }]) => [title, [params], exception] | ||
) | ||
|
||
describe(`Test capacity validator`, () => { | ||
test.each(fixtureTable)(`%s`, (_title, [params], exception) => { | ||
if (exception) { | ||
expect.assertions(2) | ||
try { | ||
validateCapacity(params) | ||
} catch (err) { | ||
expect(isErrorWithI18n(err)).toBeTruthy() | ||
expect((err as { code: number }).code).toBe(exception) | ||
} | ||
} else { | ||
expect.assertions(1) | ||
expect(validateCapacity(params)).toBeTruthy() | ||
} | ||
}) | ||
}) |
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,19 @@ | ||
import { CKBToShannonFormatter } from 'utils/formatters' | ||
import { CapacityTooSmallException } from 'exceptions' | ||
import { bytes as byteUtils } from '@ckb-lumos/codec' | ||
import { ckbCore } from 'services/chain' | ||
|
||
export const validateCapacity = (item: State.Output) => { | ||
const { amount, unit, address } = item | ||
const capacity = CKBToShannonFormatter(amount, unit) | ||
const script = ckbCore.utils.addressToScript(address as string) | ||
const size = 1 + byteUtils.concat(script.args, script.codeHash).byteLength | ||
const outputSize = 8 + byteUtils.bytify('0x').byteLength + size | ||
|
||
if (BigInt(capacity) < BigInt(outputSize) * BigInt(10 ** 8)) { | ||
throw new CapacityTooSmallException(outputSize.toString()) | ||
} | ||
|
||
return true | ||
} | ||
export default validateCapacity |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.