[#225] netmap: Do not emit some events in notary-enabled mode

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-03-17 16:02:56 +03:00 committed by Alex Vanin
parent a4f9d52cfc
commit f6766a144f
2 changed files with 9 additions and 16 deletions

View file

@ -233,7 +233,9 @@ func AddPeer(nodeInfo []byte) {
publicKey := nodeInfo[2:35] // offset:2, len:33
common.CheckWitness(publicKey)
runtime.Notify("AddPeer", nodeInfo)
if notaryDisabled {
runtime.Notify("AddPeer", nodeInfo)
}
return
}
@ -287,7 +289,9 @@ func UpdateState(state int, publicKey interop.PublicKey) {
// just emit the notification for alphabet.
if !notaryDisabled || len(nodeKey) == 0 {
common.CheckWitness(publicKey)
runtime.Notify("UpdateState", state, publicKey)
if notaryDisabled {
runtime.Notify("UpdateState", state, publicKey)
}
return
}

View file

@ -93,18 +93,12 @@ func TestAddPeer(t *testing.T) {
h := cAcc.Invoke(t, stackitem.Null{}, "addPeer", dummyInfo.raw)
aer := cAcc.CheckHalt(t, h)
require.Equal(t, 1, len(aer.Events))
require.Equal(t, "AddPeer", aer.Events[0].Name)
require.Equal(t, stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray(dummyInfo.raw)}),
aer.Events[0].Item)
require.Equal(t, 0, len(aer.Events))
dummyInfo.raw[0] ^= 0xFF
h = cAcc.Invoke(t, stackitem.Null{}, "addPeer", dummyInfo.raw)
aer = cAcc.CheckHalt(t, h)
require.Equal(t, 1, len(aer.Events))
require.Equal(t, "AddPeer", aer.Events[0].Name)
require.Equal(t, stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray(dummyInfo.raw)}),
aer.Events[0].Item)
require.Equal(t, 0, len(aer.Events))
c.InvokeFail(t, common.ErrWitnessFailed, "addPeer", dummyInfo.raw)
c.Invoke(t, stackitem.Null{}, "addPeerIR", dummyInfo.raw)
@ -132,12 +126,7 @@ func TestUpdateState(t *testing.T) {
h := cAcc.Invoke(t, stackitem.Null{}, "updateState", int64(2), pub)
aer := cAcc.CheckHalt(t, h)
require.Equal(t, 1, len(aer.Events))
require.Equal(t, "UpdateState", aer.Events[0].Name)
require.Equal(t, stackitem.NewArray([]stackitem.Item{
stackitem.NewBigInteger(big.NewInt(2)),
stackitem.NewByteArray(pub),
}), aer.Events[0].Item)
require.Equal(t, 0, len(aer.Events))
// Check that updating happens only after `updateState` is called by the alphabet.
s, err := cAcc.TestInvoke(t, "netmapCandidates")