More thorough tests on coin module

This commit is contained in:
Ethan Frey
2017-06-30 20:26:17 +02:00
parent 27a31953f9
commit 673b51f3b0
5 changed files with 174 additions and 6 deletions
+53
View File
@@ -0,0 +1,53 @@
package stack
import (
"bytes"
"github.com/tendermint/tmlibs/log"
"github.com/tendermint/basecoin"
)
type mockContext struct {
perms []basecoin.Actor
log.Logger
}
func MockContext() basecoin.Context {
return mockContext{
Logger: log.NewNopLogger(),
}
}
var _ basecoin.Context = mockContext{}
// WithPermissions will panic if they try to set permission without the proper app
func (c mockContext) WithPermissions(perms ...basecoin.Actor) basecoin.Context {
return mockContext{
perms: append(c.perms, perms...),
Logger: c.Logger,
}
}
func (c mockContext) HasPermission(perm basecoin.Actor) bool {
for _, p := range c.perms {
if perm.App == p.App && bytes.Equal(perm.Address, p.Address) {
return true
}
}
return false
}
// IsParent ensures that this is derived from the given secureClient
func (c mockContext) IsParent(other basecoin.Context) bool {
_, ok := other.(mockContext)
return ok
}
// Reset should clear out all permissions,
// but carry on knowledge that this is a child
func (c mockContext) Reset() basecoin.Context {
return mockContext{
Logger: c.Logger,
}
}