Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
silkaj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
silkaj
Commits
e8e67d35
Commit
e8e67d35
authored
4 years ago
by
matograine
Browse files
Options
Downloads
Patches
Plain Diff
[fix]
#356
: use pending txs first to use change txs sent beforehand.
* create related test
parent
02bc69f9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!153
[fix] #356 : use pending txs first to use change txs sent beforehand.
Pipeline
#10460
passed
4 years ago
Stage: checks
Stage: tests
Stage: coverage
Stage: deploy
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
silkaj/money.py
+2
-1
2 additions, 1 deletion
silkaj/money.py
tests/test_money.py
+90
-0
90 additions, 0 deletions
tests/test_money.py
with
92 additions
and
1 deletion
silkaj/money.py
+
2
−
1
View file @
e8e67d35
...
@@ -165,7 +165,8 @@ async def get_sources(pubkey):
...
@@ -165,7 +165,8 @@ async def get_sources(pubkey):
index
=
i
,
index
=
i
,
)
)
if
inputgenerated
not
in
listinput
:
if
inputgenerated
not
in
listinput
:
listinput
.
append
(
inputgenerated
)
# add pendings before blockchain sources for change txs
listinput
.
insert
(
0
,
inputgenerated
)
for
input
in
pending
[
"
inputs
"
]:
for
input
in
pending
[
"
inputs
"
]:
pending_sources
.
append
(
InputSource
.
from_inline
(
input
))
pending_sources
.
append
(
InputSource
.
from_inline
(
input
))
...
...
This diff is collapsed.
Click to expand it.
tests/test_money.py
+
90
−
0
View file @
e8e67d35
...
@@ -18,10 +18,100 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
...
@@ -18,10 +18,100 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
import
pytest
import
pytest
from
click.testing
import
CliRunner
from
click.testing
import
CliRunner
import
duniterpy.api.bma.tx
as
bma_tx
# had to import from wot to prevent loop dependencies
# had to import from wot to prevent loop dependencies
from
silkaj.wot
import
display_pubkey_and_checksum
from
silkaj.wot
import
display_pubkey_and_checksum
from
silkaj.cli
import
cli
from
silkaj.cli
import
cli
from
silkaj.constants
import
FAILURE_EXIT_STATUS
from
silkaj.constants
import
FAILURE_EXIT_STATUS
from
silkaj.money
import
get_sources
@pytest.mark.asyncio
async
def
test_get_sources
(
monkeypatch
):
"""
test that get_source() will :
* only use simple SIG txs
* only use blockchain sources to compute balance
* return pending txs in first positions of the sources list
"""
async
def
patched_tx_sources
(
self
,
pubkey
):
return
{
"
currency
"
:
"
g1-test
"
,
"
pubkey
"
:
"
AhRMHUxMPXSeG7qXZrE6qCdjwK9p2bu5Eqei7xAWVEDK
"
,
"
sources
"
:
[
# this source will be returned in inputlist, and its amount used.
{
"
type
"
:
"
T
"
,
"
noffset
"
:
2
,
"
identifier
"
:
"
0310F56D22F4CEF5E41B9D5CACB6E21F224B79D9398D53A4E754866435710242
"
,
"
amount
"
:
10
,
"
base
"
:
3
,
"
conditions
"
:
"
SIG(AhRMHUxMPXSeG7qXZrE6qCdjwK9p2bu5Eqei7xAWVEDK)
"
,
},
# this source will not be returned (complex unlock condition)
{
"
type
"
:
"
T
"
,
"
noffset
"
:
3
,
"
identifier
"
:
"
0D6A29451E64F468C0DB19F70D0D17F65BDCC98F3A16DD55B3755BE124B3DD6C
"
,
"
amount
"
:
30
,
"
base
"
:
3
,
"
conditions
"
:
"
(SIG(2VgEZnrGQ5hEgwoNrcXZnD9c8o5jL63LPBmJdvMyFhGe) || (SIG(AhRMHUxMPXSeG7qXZrE6qCdjwK9p2bu5Eqei7xAWVEDK) && CSV(864)))
"
,
},
],
}
async
def
patched_tx_pending
(
self
,
pubkey
):
return
{
"
currency
"
:
"
g1-test
"
,
"
pubkey
"
:
"
AhRMHUxMPXSeG7qXZrE6qCdjwK9p2bu5Eqei7xAWVEDK
"
,
"
history
"
:
{
"
sending
"
:
[],
"
received
"
:
[],
"
receiving
"
:
[],
"
sent
"
:
[],
"
pending
"
:
[
{
"
version
"
:
10
,
"
locktime
"
:
0
,
"
blockstamp
"
:
"
671977-000008B6DE75715D3D83450A957CD75F781DA8E3E8E966D42A02F59049209533
"
,
"
blockstampTime
"
:
1607363853
,
"
issuers
"
:
[
"
6upqFiJ66WV6N3bPc8x8y7rXT3syqKRmwnVyunCtEj7o
"
],
"
inputs
"
:
[
"
2739:3:D:6upqFiJ66WV6N3bPc8x8y7rXT3syqKRmwnVyunCtEj7o:664106
"
],
"
outputs
"
:
[
"
60:3:SIG(AhRMHUxMPXSeG7qXZrE6qCdjwK9p2bu5Eqei7xAWVEDK)
"
,
"
2679:3:SIG(6upqFiJ66WV6N3bPc8x8y7rXT3syqKRmwnVyunCtEj7o)
"
,
],
"
unlocks
"
:
[
"
0:SIG(0)
"
],
"
signatures
"
:
[
"
lrmzr/RkecJBOczlmkp3BNCiXejBzTnHdqmNzxQJyJDIx0UHON4jYkqVKeD77+nrOl8jVtonLt3ZYqd1fhi1Cw==
"
],
"
comment
"
:
"
DEMAIN DES L_AUBE
"
,
"
hash
"
:
"
D5A1A1AAA43FAA242CC2B19763619DA625092BB7FD23397AD362215375A920C8
"
,
"
time
"
:
None
,
"
block_number
"
:
None
,
"
received
"
:
None
,
}
],
},
}
monkeypatch
.
setattr
(
bma_tx
,
"
sources
"
,
patched_tx_sources
)
monkeypatch
.
setattr
(
bma_tx
,
"
pending
"
,
patched_tx_pending
)
listinput
,
balance
=
await
get_sources
(
"
AhRMHUxMPXSeG7qXZrE6qCdjwK9p2bu5Eqei7xAWVEDK
"
)
assert
len
(
listinput
)
==
2
# test SIG() only source is used
assert
balance
==
10000
# 10 in unitbase 3
assert
(
listinput
[
0
].
origin_id
==
"
D5A1A1AAA43FAA242CC2B19763619DA625092BB7FD23397AD362215375A920C8
"
)
def
test_balance_errors
():
def
test_balance_errors
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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