Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
iota-imt
goshimmer
Commits
8bdd1796
Commit
8bdd1796
authored
5 years ago
by
Hans Moog
Browse files
Options
Downloads
Patches
Plain Diff
Feat: added test for solidifier
parent
6a764bc4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
packages/ternary/ternary.go
+2
-2
2 additions, 2 deletions
packages/ternary/ternary.go
plugins/tangle/approvers_test.go
+23
-54
23 additions, 54 deletions
plugins/tangle/approvers_test.go
plugins/tangle/transaction.go
+30
-4
30 additions, 4 deletions
plugins/tangle/transaction.go
with
55 additions
and
60 deletions
packages/ternary/ternary.go
+
2
−
2
View file @
8bdd1796
...
...
@@ -22,7 +22,7 @@ func (trinary Trinary) CastToBytes() []byte {
}
func
(
trinary
Trinary
)
ToTrits
()
Trits
{
trits
:=
make
(
Trits
,
len
(
trinary
)
*
3
)
trits
:=
make
(
Trits
,
0
,
len
(
trinary
)
*
NUMBER_OF_TRITS_IN_A_TRYTE
)
for
_
,
char
:=
range
trinary
{
trits
=
append
(
trits
,
TRYTES_TO_TRITS_MAP
[
char
]
...
)
}
...
...
@@ -57,7 +57,7 @@ func (this Trits) ToBytes() []byte {
func
(
this
Trits
)
TrailingZeroes
()
int
{
zeros
:=
0
index
:=
len
(
this
)
-
1
for
this
[
index
]
==
0
{
for
index
>=
0
&&
this
[
index
]
==
0
{
zeros
++
index
--
...
...
This diff is collapsed.
Click to expand it.
plugins/tangle/approvers_test.go
+
23
−
54
View file @
8bdd1796
package
tangle
import
(
"
fmt
"
"
sync
"
"testing"
"time"
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/ternary"
"github.com/iotaledger/goshimmer/packages/transaction"
"github.com/iotaledger/goshimmer/plugins/gossip"
)
func
TestGetApprovers
(
t
*
testing
.
T
)
{
configureDatabase
(
nil
)
approvers
,
err
:=
GetApprovers
(
ternary
.
Trinary
(
"AA"
),
NewApprovers
)
approvers
.
Add
(
ternary
.
Trinary
(
"FF"
))
fmt
.
Println
(
approvers
)
fmt
.
Println
(
err
)
approvers1
,
err1
:=
GetApprovers
(
ternary
.
Trinary
(
"AA"
))
fmt
.
Println
(
approvers1
)
fmt
.
Println
(
err1
)
}
func
TestSolidifier
(
t
*
testing
.
T
)
{
// initialize plugin
configureDatabase
(
nil
)
configureSolidifier
(
nil
)
txData
:=
make
([]
byte
,
1572
)
txData
[
1571
]
=
1
tx
:=
transaction
.
FromBytes
(
txData
)
txData
[
1571
]
=
2
tx1
:=
transaction
.
FromBytes
(
txData
)
tx1
.
BranchTransactionHash
=
tx
.
Hash
txData
[
1571
]
=
3
tx2
:=
transaction
.
FromBytes
(
txData
)
tx2
.
BranchTransactionHash
=
tx1
.
Hash
txData
[
1571
]
=
4
tx3
:=
transaction
.
FromBytes
(
txData
)
tx3
.
BranchTransactionHash
=
tx2
.
Hash
fmt
.
Println
(
tx
.
Hash
.
ToString
())
fmt
.
Println
(
tx1
.
Hash
.
ToString
())
fmt
.
Println
(
tx2
.
Hash
.
ToString
())
fmt
.
Println
(
tx3
.
Hash
.
ToString
())
fmt
.
Println
(
"============"
)
// create transactions and chain them together
transaction1
:=
NewTransaction
(
nil
)
transaction1
.
SetNonce
(
ternary
.
Trinary
(
"99999999999999999999999999A"
))
transaction2
:=
NewTransaction
(
nil
)
transaction2
.
SetBranchTransactionHash
(
transaction1
.
GetHash
())
transaction3
:=
NewTransaction
(
nil
)
transaction3
.
SetBranchTransactionHash
(
transaction2
.
GetHash
())
transaction4
:=
NewTransaction
(
nil
)
transaction4
.
SetBranchTransactionHash
(
transaction3
.
GetHash
())
// setup event handlers
var
wg
sync
.
WaitGroup
Events
.
TransactionSolid
.
Attach
(
events
.
NewClosure
(
func
(
transaction
*
Transaction
)
{
fmt
.
Println
(
"SOLID: "
+
transaction
.
GetHash
()
)
wg
.
Done
()
}))
gossip
.
Events
.
ReceiveTransaction
.
Trigger
(
tx
)
gossip
.
Events
.
ReceiveTransaction
.
Trigger
(
tx1
)
gossip
.
Events
.
ReceiveTransaction
.
Trigger
(
tx3
)
fmt
.
Println
(
"..."
)
time
.
Sleep
(
1
*
time
.
Second
)
gossip
.
Events
.
ReceiveTransaction
.
Trigger
(
tx2
)
// issue transactions
wg
.
Add
(
4
)
gossip
.
Events
.
ReceiveTransaction
.
Trigger
(
transaction1
.
Flush
())
gossip
.
Events
.
ReceiveTransaction
.
Trigger
(
transaction2
.
Flush
())
gossip
.
Events
.
ReceiveTransaction
.
Trigger
(
transaction3
.
Flush
())
gossip
.
Events
.
ReceiveTransaction
.
Trigger
(
transaction4
.
Flush
())
time
.
Sleep
(
1
*
time
.
Second
)
// wait until all are solid
wg
.
Wait
()
}
This diff is collapsed.
Click to expand it.
plugins/tangle/transaction.go
+
30
−
4
View file @
8bdd1796
package
tangle
import
(
"math"
"sync"
"github.com/iotaledger/goshimmer/packages/curl"
"github.com/iotaledger/goshimmer/packages/errors"
"github.com/iotaledger/goshimmer/packages/ternary"
"github.com/iotaledger/goshimmer/packages/transaction"
...
...
@@ -48,6 +50,10 @@ type Transaction struct {
}
func
NewTransaction
(
rawTransaction
*
transaction
.
Transaction
)
*
Transaction
{
if
rawTransaction
==
nil
{
rawTransaction
=
transaction
.
FromBytes
(
make
([]
byte
,
int
(
math
.
Ceil
(
float64
(
transaction
.
MARSHALLED_TOTAL_SIZE
)
/
ternary
.
NUMBER_OF_TRITS_IN_A_BYTE
))))
}
return
&
Transaction
{
rawTransaction
:
rawTransaction
}
}
...
...
@@ -123,6 +129,10 @@ func (transaction *Transaction) ParseHash() ternary.Trinary {
// parses the hash from the underlying raw transaction (without locking - internal usage)
func
(
transaction
*
Transaction
)
parseHash
()
(
result
ternary
.
Trinary
)
{
if
transaction
.
modified
{
transaction
.
Flush
()
}
result
=
transaction
.
rawTransaction
.
Hash
.
ToTrinary
()
transaction
.
hash
=
&
result
...
...
@@ -500,7 +510,7 @@ func (transaction *Transaction) SetBranchTransactionHash(branchTransactionHash t
transaction
.
branchTransactionHashMutex
.
Lock
()
defer
transaction
.
branchTransactionHashMutex
.
Unlock
()
if
transaction
.
branchTransactionHash
==
nil
||
*
transaction
.
branchTransactionHash
!=
branchTransactionHash
{
*
transaction
.
branchTransactionHash
=
branchTransactionHash
transaction
.
branchTransactionHash
=
&
branchTransactionHash
transaction
.
SetModified
(
true
)
}
...
...
@@ -600,7 +610,7 @@ func (transaction *Transaction) SetNonce(nonce ternary.Trinary) {
transaction
.
nonceMutex
.
Lock
()
defer
transaction
.
nonceMutex
.
Unlock
()
if
transaction
.
nonce
==
nil
||
*
transaction
.
nonce
!=
nonce
{
*
transaction
.
nonce
=
nonce
transaction
.
nonce
=
&
nonce
transaction
.
SetModified
(
true
)
}
...
...
@@ -618,8 +628,10 @@ func (transaction *Transaction) ParseNonce() ternary.Trinary {
}
// parses the nonce from the underlying raw transaction (without locking - internal usage)
func
(
transaction
*
Transaction
)
parseNonce
()
ternary
.
Trinary
{
*
transaction
.
nonce
=
transaction
.
rawTransaction
.
Nonce
.
ToTrinary
()
func
(
transaction
*
Transaction
)
parseNonce
()
(
result
ternary
.
Trinary
)
{
result
=
transaction
.
rawTransaction
.
Nonce
.
ToTrinary
()
transaction
.
nonce
=
&
result
return
*
transaction
.
nonce
}
...
...
@@ -644,6 +656,20 @@ func (transaction *Transaction) SetModified(modified bool) {
// region database functions ///////////////////////////////////////////////////////////////////////////////////////////
// Applies the current values to the
func
(
this
*
Transaction
)
Flush
()
*
transaction
.
Transaction
{
if
this
.
branchTransactionHash
!=
nil
{
copy
(
this
.
rawTransaction
.
Trits
[
transaction
.
BRANCH_TRANSACTION_HASH_OFFSET
:
transaction
.
BRANCH_TRANSACTION_HASH_END
],
this
.
branchTransactionHash
.
ToTrits
()[
:
transaction
.
BRANCH_TRANSACTION_HASH_SIZE
])
}
if
this
.
nonce
!=
nil
{
copy
(
this
.
rawTransaction
.
Trits
[
transaction
.
NONCE_OFFSET
:
transaction
.
NONCE_END
],
this
.
nonce
.
ToTrits
()[
:
transaction
.
NONCE_SIZE
])
}
this
.
rawTransaction
.
Hash
=
<-
curl
.
CURLP81
.
Hash
(
this
.
rawTransaction
.
Trits
)
return
this
.
rawTransaction
}
func
(
transaction
*
Transaction
)
Store
()
errors
.
IdentifiableError
{
if
err
:=
transactionDatabase
.
Set
(
transaction
.
rawTransaction
.
Hash
.
ToBytes
(),
transaction
.
rawTransaction
.
Bytes
);
err
!=
nil
{
return
ErrDatabaseError
.
Derive
(
err
,
"failed to store the transaction"
)
...
...
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