FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
beam/node/functionaltests/double_spending_test.cpp at master · pilot-SyS/beam · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
pilot-SyS
/
beam
Public
forked from
BeamMW/beam
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
beam
/
node
/
functionaltests
/
double_spending_test.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
126 lines (108 loc) · 3.06 KB
Breadcrumbs
beam
/
node
/
functionaltests
/
double_spending_test.cpp
Copy path
File metadata and controls
126 lines (108 loc) · 3.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
Copyright 2018 The Beam Team
//
//
Licensed under the Apache License, Version 2.0 (the "License");
//
you may not use this file except in compliance with the License.
//
You may obtain a copy of the License at
//
//
http://www.apache.org/licenses/LICENSE-2.0
//
//
Unless required by applicable law or agreed to in writing, software
//
distributed under the License is distributed on an "AS IS" BASIS,
//
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
See the License for the specific language governing permissions and
//
limitations under the License.
#
include
"
node/node.h
"
#
include
"
utility/logger.h
"
#
include
"
tools/base_node_connection.h
"
#
include
"
tools/coins_checker.h
"
#
include
"
tools/tx_generator.h
"
using
namespace
beam
;
class
TestNodeConnection
:
public
BaseTestNode
{
public:
TestNodeConnection
(
int
argc,
char
* argv[]);
private:
void
GenerateTests
()
override
;
void
OnMsg
(proto::NewTip&&)
override
;
void
OnMsg
(proto::Boolean&&)
override
;
private:
bool
m_IsInit;
bool
m_IsNeedToCheckOut;
unsigned
int
m_Counter;
TxGenerator m_Generator;
CoinsChecker m_CoinsChecker;
};
TestNodeConnection::TestNodeConnection
(
int
argc,
char
* argv[])
: BaseTestNode(argc, argv)
, m_IsInit(
false
)
, m_IsNeedToCheckOut(
false
)
, m_Counter(
0
)
, m_Generator(*m_pKdf)
, m_CoinsChecker(argc, argv)
{
m_Timeout =
5
*
60
*
1000
;
}
void
TestNodeConnection::GenerateTests
()
{
m_Tests.
push_back
([
this
]
{
m_CoinsChecker.
InitChecker
();
});
}
void
TestNodeConnection::OnMsg
(proto::NewTip&& msg)
{
Block::SystemState::
ID
id;
msg.
m_Description
.
get_ID
(id);
LOG_INFO
() <<
"
NewTip:
"
<< id;
if
(!m_IsInit)
{
m_IsInit =
true
;
m_Generator.
GenerateInputInTx
(msg.
m_Description
.
m_Height
-
70
,
Rules::get
().
CoinbaseEmission
);
m_Generator.
GenerateInputInTx
(msg.
m_Description
.
m_Height
-
70
,
Rules::get
().
CoinbaseEmission
);
m_Generator.
GenerateOutputInTx
(msg.
m_Description
.
m_Height
+
1
,
Rules::get
().
CoinbaseEmission
);
m_Generator.
GenerateKernel
(msg.
m_Description
.
m_Height
+
5
,
Rules::get
().
CoinbaseEmission
);
m_Generator.
Sort
();
Send
(m_Generator.
GetTransaction
());
}
if
(m_IsNeedToCheckOut)
{
if
(++m_Counter >=
2
)
{
m_CoinsChecker.
Check
(m_Generator.
GenerateInputsFromOutputs
(),
[
this
](
bool
isOk, Height maturity)
{
if
(isOk)
{
LOG_INFO
() <<
"
Failed: utxo is valid
"
;
}
else
{
LOG_INFO
() <<
"
Ok: utxo is not valid
"
;
m_Failed =
true
;
}
io::Reactor::get_Current
().
stop
();
}
);
}
}
}
void
TestNodeConnection::OnMsg
(proto::Boolean&& msg)
{
LOG_INFO
() <<
"
Boolean: value =
"
<< msg.
m_Value
;
if
(!msg.
m_Value
)
{
LOG_INFO
() <<
"
Failed: tx is invalid
"
;
m_Failed =
true
;
io::Reactor::get_Current
().
stop
();
return
;
}
m_IsNeedToCheckOut =
true
;
}
int
main
(
int
argc,
char
* argv[])
{
int
logLevel =
LOG_LEVEL_DEBUG
;
auto
logger =
Logger::create
(logLevel, logLevel);
TestNodeConnection
connection
(argc, argv);
connection.
Run
();
return
connection.
CheckOnFailed
();
}
Back
|
FazBrowse Home
|
New Git URL