Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
substrate-api-sidecar
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
substrate-api-sidecar
Commits
49dc2f43
Unverified
Commit
49dc2f43
authored
2 years ago
by
Tarik Gul
Browse files
Options
Downloads
Patches
Plain Diff
write tests and adjust logic to include tips into partial fee
parent
131aeffa
Branches
986
No related merge requests found
Pipeline
#203501
waiting for manual action with stages
Stage:
Stage:
in 1 minute and 26 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/services/blocks/BlocksService.spec.ts
+15
-0
15 additions, 0 deletions
src/services/blocks/BlocksService.spec.ts
src/services/blocks/BlocksService.ts
+10
-6
10 additions, 6 deletions
src/services/blocks/BlocksService.ts
with
25 additions
and
6 deletions
src/services/blocks/BlocksService.spec.ts
+
15
−
0
View file @
49dc2f43
...
...
@@ -20,6 +20,7 @@ import { PromiseRpcResult } from '@polkadot/api-base/types/rpc';
import
{
GenericExtrinsic
}
from
'
@polkadot/types
'
;
import
{
GenericCall
}
from
'
@polkadot/types/generic
'
;
import
{
BlockHash
,
Hash
,
SignedBlock
}
from
'
@polkadot/types/interfaces
'
;
import
{
Compact
}
from
'
@polkadot/types-codec/base
'
;
import
{
BadRequest
}
from
'
http-errors
'
;
import
LRU
from
'
lru-cache
'
;
...
...
@@ -44,6 +45,7 @@ import {
constructEvent
,
treasuryEvent
,
withdrawEvent
,
withdrawEventForTip
,
}
from
'
../test-helpers/mock/data/mockEventData
'
;
import
{
validators789629Hex
}
from
'
../test-helpers/mock/data/validators789629Hex
'
;
import
{
parseNumberOrThrow
}
from
'
../test-helpers/mock/parseNumberOrThrow
'
;
...
...
@@ -589,6 +591,19 @@ describe('BlocksService', () => {
expect
(
response
).
toStrictEqual
(
expectedResponse
);
});
it
(
'
Should retrieve the correct fee for balances:withdraw events with a tip
'
,
()
=>
{
const
expectedResponse
=
{
partialFee
:
'
1681144907847007
'
};
const
fee
=
polkadotRegistry
.
createType
(
'
Balance
'
,
'
1675415067070856
'
);
const
tip
=
new
Compact
(
polkadotRegistry
,
'
u64
'
,
5729827274000
);
const
response
=
blocksService
[
'
getPartialFeeByEvents
'
](
withdrawEventForTip
,
fee
,
tip
);
expect
(
response
).
toStrictEqual
(
expectedResponse
);
});
it
(
'
Should error correctly when there is no fee in the events
'
,
()
=>
{
const
expectedResponseWithError
=
{
...
expectedResponse
,
...
...
This diff is collapsed.
Click to expand it.
src/services/blocks/BlocksService.ts
+
10
−
6
View file @
49dc2f43
...
...
@@ -533,9 +533,11 @@ export class BlocksService extends AbstractService {
const
dataArr
=
withdrawEvent
[
0
].
data
.
toJSON
();
if
(
Array
.
isArray
(
dataArr
))
{
const
fee
=
(
dataArr
as
Array
<
number
>
)[
dataArr
.
length
-
1
];
const
adjustedFee
=
tip
?
tip
.
toBn
().
add
(
new
BN
(
fee
))
:
new
BN
(
fee
);
const
adjustedPartialFee
=
tip
?
tip
.
toBn
().
add
(
partialFee
)
:
partialFee
;
// The difference between values is 00.00001% or less so they are alike.
if
(
this
.
areFeesSimilar
(
adjusted
Fee
,
p
artialFee
))
{
if
(
this
.
areFeesSimilar
(
new
BN
(
fee
),
adjusted
P
artialFee
))
{
return
{
partialFee
:
fee
.
toString
(),
};
...
...
@@ -549,9 +551,11 @@ export class BlocksService extends AbstractService {
const
dataArr
=
treasuryEvent
[
0
].
data
.
toJSON
();
if
(
Array
.
isArray
(
dataArr
))
{
const
fee
=
(
dataArr
as
Array
<
number
>
)[
0
];
const
adjustedFee
=
tip
?
tip
.
toBn
().
add
(
new
BN
(
fee
))
:
new
BN
(
fee
);
const
adjustedPartialFee
=
tip
?
tip
.
toBn
().
add
(
partialFee
)
:
partialFee
;
// The difference between values is 00.00001% or less so they are alike.
if
(
this
.
areFeesSimilar
(
adjusted
Fee
,
p
artialFee
))
{
if
(
this
.
areFeesSimilar
(
new
BN
(
fee
),
adjusted
P
artialFee
))
{
return
{
partialFee
:
fee
.
toString
(),
};
...
...
@@ -567,9 +571,9 @@ export class BlocksService extends AbstractService {
({
data
})
=>
(
sumOfFees
=
sumOfFees
.
add
(
new
BN
(
data
[
data
.
length
-
1
].
toString
())))
);
const
adjustedFee
=
tip
?
tip
.
toBn
().
add
(
sumOf
Fee
s
)
:
sumOf
Fee
s
;
const
adjusted
Partial
Fee
=
tip
?
tip
.
toBn
().
add
(
partial
Fee
)
:
partial
Fee
;
// The difference between values is 00.00001% or less so they are alike.
if
(
this
.
areFeesSimilar
(
adjusted
Fee
,
p
artialFee
))
{
if
(
this
.
areFeesSimilar
(
sumOfFees
,
adjusted
P
artialFee
))
{
return
{
partialFee
:
sumOfFees
.
toString
(),
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment