Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
burrow
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hang Yu
burrow
Commits
c69ced35
Unverified
Commit
c69ced35
authored
6 years ago
by
Silas Davis
Browse files
Options
Downloads
Patches
Plain Diff
Added state cache test
Signed-off-by:
Silas Davis
<
silas@monax.io
>
parent
60a7686a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
account/state/state_cache_test.go
+77
-16
77 additions, 16 deletions
account/state/state_cache_test.go
with
77 additions
and
16 deletions
account/state/state_cache_test.go
+
77
−
16
View file @
c69ced35
...
@@ -6,37 +6,75 @@ import (
...
@@ -6,37 +6,75 @@ import (
acm
"github.com/hyperledger/burrow/account"
acm
"github.com/hyperledger/burrow/account"
"github.com/hyperledger/burrow/binary"
"github.com/hyperledger/burrow/binary"
"github.com/hyperledger/burrow/execution/evm/asm"
"github.com/hyperledger/burrow/permission"
"github.com/hyperledger/burrow/permission"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
func
TestStateCache_GetAccount
(
t
*
testing
.
T
)
{
func
TestStateCache_GetAccount
(
t
*
testing
.
T
)
{
acc
:=
acm
.
NewConcreteAccountFromSecret
(
"foo"
)
// Build backend states for read and write
acc
.
Permissions
.
Base
.
Perms
=
permission
.
AddRole
|
permission
.
Send
readBackend
:=
testAccounts
()
acc
.
Permissions
.
Base
.
SetBit
=
acc
.
Permissions
.
Base
.
Perms
writeBackend
:=
NewCache
(
newTestState
())
state
:=
combine
(
account
(
acc
.
Account
(),
"I AM A KEY"
,
"NO YOU ARE A KEY"
))
cache
:=
NewCache
(
readBackend
)
cache
:=
NewCache
(
state
)
accOut
,
err
:=
cache
.
GetAccount
(
acc
.
Address
)
acc
:=
readBackend
.
Accounts
[
addressOf
(
"acc1"
)]
accOut
,
err
:=
cache
.
GetAccount
(
acc
.
Address
())
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
cache
.
UpdateAccount
(
accOut
)
cache
.
UpdateAccount
(
accOut
)
accEnc
,
err
:=
acc
.
Encode
()
assert
.
Equal
(
t
,
acm
.
AsConcreteAccount
(
acc
),
acm
.
AsConcreteAccount
(
accOut
))
accEncOut
,
err
:=
accOut
.
Encode
()
assert
.
Equal
(
t
,
accEnc
,
accEncOut
)
assert
.
Equal
(
t
,
acc
.
Permissions
,
accOut
.
Permissions
())
cacheBackend
:=
NewCache
(
newTestState
())
err
=
cache
.
Sync
(
writeBackend
)
err
=
cache
.
Sync
(
cacheBackend
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
accOut
,
err
=
cach
eBackend
.
GetAccount
(
acc
.
Address
)
accOut
,
err
=
writ
eBackend
.
GetAccount
(
acc
.
Address
()
)
require
.
NotNil
(
t
,
accOut
)
require
.
NotNil
(
t
,
accOut
)
accEncOut
,
err
=
accOut
.
Encode
()
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
ac
cEnc
,
accEn
cOut
)
assert
.
Equal
(
t
,
ac
m
.
AsConcreteAccount
(
acc
),
acm
.
AsConcreteAccount
(
ac
cOut
)
)
}
}
func
TestStateCache_UpdateAccount
(
t
*
testing
.
T
)
{
func
TestStateCache_UpdateAccount
(
t
*
testing
.
T
)
{
// Build backend states for read and write
backend
:=
NewCache
(
newTestState
())
cache
:=
NewCache
(
backend
)
// Create acccount
accNew
:=
acm
.
NewConcreteAccountFromSecret
(
"accNew"
)
balance
:=
uint64
(
24
)
accNew
.
Balance
=
balance
err
:=
cache
.
UpdateAccount
(
accNew
.
Account
())
require
.
NoError
(
t
,
err
)
// Check cache
accNewOut
,
err
:=
cache
.
GetAccount
(
accNew
.
Address
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
balance
,
accNewOut
.
Balance
())
// Check not stored in backend
accNewOut
,
err
=
backend
.
GetAccount
(
accNew
.
Address
)
require
.
NoError
(
t
,
err
)
assert
.
Nil
(
t
,
accNewOut
)
// Check syncs to backend
err
=
cache
.
Sync
(
backend
)
require
.
NoError
(
t
,
err
)
accNewOut
,
err
=
backend
.
GetAccount
(
accNew
.
Address
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
balance
,
accNewOut
.
Balance
())
// Alter in cache
newBalance
:=
uint64
(
100029
)
accNew
.
Balance
=
newBalance
err
=
cache
.
UpdateAccount
(
accNew
.
Account
())
require
.
NoError
(
t
,
err
)
// Check cache
accNewOut
,
err
=
cache
.
GetAccount
(
accNew
.
Address
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
newBalance
,
accNewOut
.
Balance
())
// Check backend unchanged
accNewOut
,
err
=
backend
.
GetAccount
(
accNew
.
Address
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
balance
,
accNewOut
.
Balance
())
}
}
func
TestStateCache_RemoveAccount
(
t
*
testing
.
T
)
{
func
TestStateCache_RemoveAccount
(
t
*
testing
.
T
)
{
...
@@ -54,7 +92,30 @@ func TestStateCache_Sync(t *testing.T) {
...
@@ -54,7 +92,30 @@ func TestStateCache_Sync(t *testing.T) {
func
TestStateCache_get
(
t
*
testing
.
T
)
{
func
TestStateCache_get
(
t
*
testing
.
T
)
{
}
}
// TODO: write tests as part of feature branch
func
testAccounts
()
*
testState
{
acc1
:=
acm
.
NewConcreteAccountFromSecret
(
"acc1"
)
acc1
.
Permissions
.
Base
.
Perms
=
permission
.
AddRole
|
permission
.
Send
acc1
.
Permissions
.
Base
.
SetBit
=
acc1
.
Permissions
.
Base
.
Perms
acc2
:=
acm
.
NewConcreteAccountFromSecret
(
"acc2"
)
acc2
.
Permissions
.
Base
.
Perms
=
permission
.
AddRole
|
permission
.
Send
acc2
.
Permissions
.
Base
.
SetBit
=
acc1
.
Permissions
.
Base
.
Perms
acc2
.
Code
,
_
=
acm
.
NewBytecode
(
asm
.
PUSH1
,
0x20
)
cache
:=
combine
(
account
(
acc1
.
Account
(),
"I AM A KEY"
,
"NO YOU ARE A KEY"
),
account
(
acc2
.
Account
(),
"ducks"
,
"have lucks"
,
"chickens"
,
"just cluck"
),
)
return
cache
}
func
addressOf
(
secret
string
)
acm
.
Address
{
return
acm
.
NewConcreteAccountFromSecret
(
secret
)
.
Address
}
// testState StateIterable
type
testState
struct
{
type
testState
struct
{
Accounts
map
[
acm
.
Address
]
acm
.
Account
Accounts
map
[
acm
.
Address
]
acm
.
Account
Storage
map
[
acm
.
Address
]
map
[
binary
.
Word256
]
binary
.
Word256
Storage
map
[
acm
.
Address
]
map
[
binary
.
Word256
]
binary
.
Word256
...
...
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