Merge pull request #2155 from nspcc-dev/block-native

native/policy: disallow blocking native contracts
This commit is contained in:
Roman Khimov 2021-09-03 13:12:13 +03:00 committed by GitHub
commit bb7136e753
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View file

@ -319,6 +319,11 @@ func (p *Policy) blockAccount(ic *interop.Context, args []stackitem.Item) stacki
panic("invalid committee signature")
}
hash := toUint160(args[0])
for i := range ic.Natives {
if ic.Natives[i].Metadata().Hash == hash {
panic("cannot block native contract")
}
}
if p.IsBlockedInternal(ic.DAO, hash) {
return stackitem.NewBool(false)
}

View file

@ -201,18 +201,25 @@ func TestBlockedAccounts(t *testing.T) {
neoHash := chain.contracts.NEO.Metadata().Hash
res, err := invokeContractMethodGeneric(chain, 100000000, policyHash, "blockAccount", true, neoHash.BytesBE())
require.NoError(t, err)
checkFAULTState(t, res)
cs, _ := getTestContractState(chain)
require.NoError(t, chain.contracts.Management.PutContractState(chain.dao, cs))
res, err = invokeContractMethodGeneric(chain, 100000000, policyHash, "blockAccount", true, cs.Hash.BytesBE())
require.NoError(t, err)
checkResult(t, res, stackitem.NewBool(true))
res, err = invokeContractMethodGeneric(chain, 100000000, neoHash, "balanceOf", true, account.BytesBE())
res, err = invokeContractMethod(chain, 100000000, cs.Hash, "justReturn")
require.NoError(t, err)
checkFAULTState(t, res)
res, err = invokeContractMethodGeneric(chain, 100000000, policyHash, "unblockAccount", true, neoHash.BytesBE())
res, err = invokeContractMethodGeneric(chain, 100000000, policyHash, "unblockAccount", true, cs.Hash.BytesBE())
require.NoError(t, err)
checkResult(t, res, stackitem.NewBool(true))
res, err = invokeContractMethodGeneric(chain, 100000000, neoHash, "balanceOf", true, account.BytesBE())
res, err = invokeContractMethod(chain, 100000000, cs.Hash, "justReturn")
require.NoError(t, err)
checkResult(t, res, stackitem.Make(0))
checkResult(t, res, stackitem.Null{})
})
}