ability to swap sender on mock context
@@ -13,7 +13,9 @@ type FakeContext struct {
data map[string][]byte
}
-func CreateFakeContext(caller, address loom.Address) Context {
+var _ Context = &FakeContext{}
+
+func CreateFakeContext(caller, address loom.Address) *FakeContext {
return &FakeContext{
caller: caller,
address: address,
@@ -21,59 +23,67 @@ func CreateFakeContext(caller, address loom.Address) Context {
}
}
-func (c FakeContext) Call(addr loom.Address, input []byte) ([]byte, error) {
+func (c *FakeContext) WithSender(caller loom.Address) Context {
+ return &FakeContext{
+ caller: caller,
+ address: c.address,
+ data: c.data,
+ }
+}
+
+func (c *FakeContext) Call(addr loom.Address, input []byte) ([]byte, error) {
return nil, nil
}
-func (c FakeContext) StaticCall(addr loom.Address, input []byte) ([]byte, error) {
+func (c *FakeContext) StaticCall(addr loom.Address, input []byte) ([]byte, error) {
return nil, nil
}
-func (c FakeContext) Resolve(name string) (loom.Address, error) {
+func (c *FakeContext) Resolve(name string) (loom.Address, error) {
return loom.Address{}, nil
}
-func (c FakeContext) ValidatorPower(pubKey []byte) int64 {
+func (c *FakeContext) ValidatorPower(pubKey []byte) int64 {
return 0
}
-func (c FakeContext) Message() Message {
+func (c *FakeContext) Message() Message {
return Message{
Sender: c.caller,
}
}
-func (c FakeContext) Block() types.BlockHeader {
+func (c *FakeContext) Block() types.BlockHeader {
return types.BlockHeader{}
}
-func (c FakeContext) ContractAddress() loom.Address {
+func (c *FakeContext) ContractAddress() loom.Address {
return c.address
}
-func (c FakeContext) Now() time.Time {
+func (c *FakeContext) Now() time.Time {
return time.Unix(0, 0)
}
-func (c FakeContext) Emit(event []byte) {
+func (c *FakeContext) Emit(event []byte) {
}
-func (c FakeContext) Get(key []byte) []byte {
+func (c *FakeContext) Get(key []byte) []byte {
v, _ := c.data[string(key)]
return v
}
-func (c FakeContext) Has(key []byte) bool {
+func (c *FakeContext) Has(key []byte) bool {
_, ok := c.data[string(key)]
return ok
}
-func (c FakeContext) Set(key []byte, value []byte) {
+func (c *FakeContext) Set(key []byte, value []byte) {
c.data[string(key)] = value
}
-func (c FakeContext) Delete(key []byte) {
+func (c *FakeContext) Delete(key []byte) {
}
-func (c FakeContext) SetValidatorPower(pubKey []byte, power int64) {
+func (c *FakeContext) SetValidatorPower(pubKey []byte, power int64) {
}
