Fix tests for unique inner ring invoke checker

This commit is contained in:
alexvanin 2020-06-17 12:54:41 +03:00
parent dc84dde87b
commit f10d346925
2 changed files with 17 additions and 2 deletions

View file

@ -434,7 +434,7 @@ func delSerializedIR(ctx storage.Context, key string, value []byte) bool {
return false return false
} }
// isInnerRingInvoker returns public key of inner ring node that invoked contract. // innerRingInvoker returns public key of inner ring node that invoked contract.
func innerRingInvoker(ir []node) []byte { func innerRingInvoker(ir []node) []byte {
for i := 0; i < len(ir); i++ { for i := 0; i < len(ir); i++ {
node := ir[i] node := ir[i]

View file

@ -44,6 +44,7 @@ func TestContract(t *testing.T) {
contract := initGoContract(t, contractTemplate, nodeCount) contract := initGoContract(t, contractTemplate, nodeCount)
plug.cgas[contractStr] = util.Fixed8FromInt64(1000) plug.cgas[contractStr] = util.Fixed8FromInt64(1000)
plug.invokeKey = crypto.MarshalPublicKey(&contract.privs[0].PublicKey)
var args []interface{} var args []interface{}
for i := range contract.privs { for i := range contract.privs {
@ -107,6 +108,7 @@ func TestContract(t *testing.T) {
// call it threshold amount of times // call it threshold amount of times
for i := 0; i < 2*nodeCount/3+1; i++ { for i := 0; i < 2*nodeCount/3+1; i++ {
plug.invokeKey = crypto.MarshalPublicKey(&contract.privs[i].PublicKey)
v := initVM(contract, plug) v := initVM(contract, plug)
loadArg(t, v, "Cheque", []interface{}{id, user, int(gas), lockAcc}) loadArg(t, v, "Cheque", []interface{}{id, user, int(gas), lockAcc})
@ -260,6 +262,7 @@ type storagePlugin struct {
interops map[uint32]vm.InteropFunc interops map[uint32]vm.InteropFunc
storageOps []kv storageOps []kv
notify []interface{} notify []interface{}
invokeKey []byte
} }
func newStoragePlugin(t *testing.T) *storagePlugin { func newStoragePlugin(t *testing.T) *storagePlugin {
@ -290,6 +293,7 @@ func newStoragePlugin(t *testing.T) *storagePlugin {
} }
s.interops[getID("System.ExecutionEngine.GetScriptContainer")] = s.GetScriptContainer s.interops[getID("System.ExecutionEngine.GetScriptContainer")] = s.GetScriptContainer
s.interops[getID("Neo.Transaction.GetHash")] = s.GetHash s.interops[getID("Neo.Transaction.GetHash")] = s.GetHash
s.interops[getID("Neo.Blockchain.GetHeight")] = s.GetHeight
return s return s
} }
@ -402,7 +406,13 @@ func (s *storagePlugin) GetTrigger(v *vm.VM) error {
} }
func (s *storagePlugin) CheckWitness(v *vm.VM) error { func (s *storagePlugin) CheckWitness(v *vm.VM) error {
v.Estack().PushVal(true) key := v.Estack().Pop().Value().([]byte)
if bytes.Equal(key, s.invokeKey) {
v.Estack().PushVal(true)
} else {
v.Estack().PushVal(false)
}
return nil return nil
} }
@ -423,6 +433,11 @@ func (s *storagePlugin) GetHash(v *vm.VM) error {
return nil return nil
} }
func (s *storagePlugin) GetHeight(v *vm.VM) error {
v.Estack().PushVal(42)
return nil
}
func (s *storagePlugin) logStorage(op string, key, value []byte) { func (s *storagePlugin) logStorage(op string, key, value []byte) {
s.storageOps = append(s.storageOps, kv{ s.storageOps = append(s.storageOps, kv{
Operation: op, Operation: op,