forked from TrueCloudLab/frostfs-node
[#975] morph/event: Update notary preparator tests
Now includes testcases for notary requests with 3 and 4 witnesses. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
a0ff5b1bf8
commit
20f0b29a6e
1 changed files with 117 additions and 51 deletions
|
@ -69,7 +69,7 @@ func TestPrepare_IncorrectScript(t *testing.T) {
|
||||||
emit.Bytes(bw.BinWriter, scriptHash.BytesBE())
|
emit.Bytes(bw.BinWriter, scriptHash.BytesBE())
|
||||||
emit.Syscall(bw.BinWriter, interopnames.SystemContractCallNative) // any != interopnames.SystemContractCall
|
emit.Syscall(bw.BinWriter, interopnames.SystemContractCallNative) // any != interopnames.SystemContractCall
|
||||||
|
|
||||||
nr := correctNR(bw.Bytes())
|
nr := correctNR(bw.Bytes(), false)
|
||||||
|
|
||||||
_, err := preparator.Prepare(nr)
|
_, err := preparator.Prepare(nr)
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ func TestPrepare_IncorrectScript(t *testing.T) {
|
||||||
emit.Bytes(bw.BinWriter, scriptHash.BytesBE())
|
emit.Bytes(bw.BinWriter, scriptHash.BytesBE())
|
||||||
emit.Syscall(bw.BinWriter, interopnames.SystemContractCall)
|
emit.Syscall(bw.BinWriter, interopnames.SystemContractCall)
|
||||||
|
|
||||||
nr := correctNR(bw.Bytes())
|
nr := correctNR(bw.Bytes(), false)
|
||||||
|
|
||||||
_, err := preparator.Prepare(nr)
|
_, err := preparator.Prepare(nr)
|
||||||
|
|
||||||
|
@ -129,12 +129,14 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
addW bool // additional witness for non alphabet invocations
|
||||||
mTX mTX
|
mTX mTX
|
||||||
fbTX fbTX
|
fbTX fbTX
|
||||||
expErr error
|
expErr error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "incorrect witness amount",
|
name: "incorrect witness amount",
|
||||||
|
addW: false,
|
||||||
mTX: mTX{
|
mTX: mTX{
|
||||||
scripts: []transaction.Witness{{}},
|
scripts: []transaction.Witness{{}},
|
||||||
},
|
},
|
||||||
|
@ -142,6 +144,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "not dummy invocation script",
|
name: "not dummy invocation script",
|
||||||
|
addW: false,
|
||||||
mTX: mTX{
|
mTX: mTX{
|
||||||
scripts: []transaction.Witness{
|
scripts: []transaction.Witness{
|
||||||
{},
|
{},
|
||||||
|
@ -155,6 +158,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "incorrect main TX signers amount",
|
name: "incorrect main TX signers amount",
|
||||||
|
addW: false,
|
||||||
mTX: mTX{
|
mTX: mTX{
|
||||||
sigs: []transaction.Signer{{}},
|
sigs: []transaction.Signer{{}},
|
||||||
},
|
},
|
||||||
|
@ -162,6 +166,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "incorrect main TX Alphabet signer",
|
name: "incorrect main TX Alphabet signer",
|
||||||
|
addW: false,
|
||||||
mTX: mTX{
|
mTX: mTX{
|
||||||
sigs: []transaction.Signer{
|
sigs: []transaction.Signer{
|
||||||
{},
|
{},
|
||||||
|
@ -175,6 +180,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "incorrect main TX attribute amount",
|
name: "incorrect main TX attribute amount",
|
||||||
|
addW: false,
|
||||||
mTX: mTX{
|
mTX: mTX{
|
||||||
attrs: []transaction.Attribute{{}, {}},
|
attrs: []transaction.Attribute{{}, {}},
|
||||||
},
|
},
|
||||||
|
@ -182,6 +188,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "incorrect main TX attribute",
|
name: "incorrect main TX attribute",
|
||||||
|
addW: false,
|
||||||
mTX: mTX{
|
mTX: mTX{
|
||||||
attrs: []transaction.Attribute{
|
attrs: []transaction.Attribute{
|
||||||
{
|
{
|
||||||
|
@ -195,6 +202,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "incorrect main TX proxy witness",
|
name: "incorrect main TX proxy witness",
|
||||||
|
addW: false,
|
||||||
mTX: mTX{
|
mTX: mTX{
|
||||||
scripts: []transaction.Witness{
|
scripts: []transaction.Witness{
|
||||||
{
|
{
|
||||||
|
@ -210,6 +218,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "incorrect main TX Alphabet witness",
|
name: "incorrect main TX Alphabet witness",
|
||||||
|
addW: false,
|
||||||
mTX: mTX{
|
mTX: mTX{
|
||||||
scripts: []transaction.Witness{
|
scripts: []transaction.Witness{
|
||||||
{},
|
{},
|
||||||
|
@ -224,6 +233,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "incorrect main TX Notary witness",
|
name: "incorrect main TX Notary witness",
|
||||||
|
addW: false,
|
||||||
mTX: mTX{
|
mTX: mTX{
|
||||||
scripts: []transaction.Witness{
|
scripts: []transaction.Witness{
|
||||||
{},
|
{},
|
||||||
|
@ -240,6 +250,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "incorrect fb TX attributes amount",
|
name: "incorrect fb TX attributes amount",
|
||||||
|
addW: false,
|
||||||
fbTX: fbTX{
|
fbTX: fbTX{
|
||||||
attrs: []transaction.Attribute{{}},
|
attrs: []transaction.Attribute{{}},
|
||||||
},
|
},
|
||||||
|
@ -247,6 +258,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "incorrect fb TX attributes",
|
name: "incorrect fb TX attributes",
|
||||||
|
addW: false,
|
||||||
fbTX: fbTX{
|
fbTX: fbTX{
|
||||||
attrs: []transaction.Attribute{{}, {}, {}},
|
attrs: []transaction.Attribute{{}, {}, {}},
|
||||||
},
|
},
|
||||||
|
@ -254,6 +266,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "expired fb TX",
|
name: "expired fb TX",
|
||||||
|
addW: false,
|
||||||
fbTX: fbTX{
|
fbTX: fbTX{
|
||||||
[]transaction.Attribute{
|
[]transaction.Attribute{
|
||||||
{},
|
{},
|
||||||
|
@ -268,6 +281,36 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
},
|
},
|
||||||
expErr: ErrMainTXExpired,
|
expErr: ErrMainTXExpired,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "incorrect invoker TX Alphabet witness",
|
||||||
|
addW: true,
|
||||||
|
mTX: mTX{
|
||||||
|
scripts: []transaction.Witness{
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
VerificationScript: alphaVerificationScript,
|
||||||
|
InvocationScript: dummyInvocationScript,
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expErr: errIncorrectInvokerWitnesses,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "incorrect main TX attribute with invoker",
|
||||||
|
addW: true,
|
||||||
|
mTX: mTX{
|
||||||
|
attrs: []transaction.Attribute{
|
||||||
|
{
|
||||||
|
Value: &transaction.NotaryAssisted{
|
||||||
|
NKeys: uint8(len(alphaKeys) + 2),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expErr: errIncorrectAttribute,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
preparator := notaryPreparator(
|
preparator := notaryPreparator(
|
||||||
|
@ -284,7 +327,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
correctNR := correctNR(nil)
|
correctNR := correctNR(nil, test.addW)
|
||||||
incorrectNR = setIncorrectFields(*correctNR, test.mTX, test.fbTX)
|
incorrectNR = setIncorrectFields(*correctNR, test.mTX, test.fbTX)
|
||||||
|
|
||||||
_, err = preparator.Prepare(&incorrectNR)
|
_, err = preparator.Prepare(&incorrectNR)
|
||||||
|
@ -328,7 +371,9 @@ func TestPrepare_CorrectNR(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
nr := correctNR(script(test.hash, test.method, test.args...))
|
for i := 0; i < 1; i++ { // run tests against 3 and 4 witness NR
|
||||||
|
additionalWitness := i == 0
|
||||||
|
nr := correctNR(script(test.hash, test.method, test.args...), additionalWitness)
|
||||||
|
|
||||||
event, err := preparator.Prepare(nr)
|
event, err := preparator.Prepare(nr)
|
||||||
|
|
||||||
|
@ -363,6 +408,7 @@ func TestPrepare_CorrectNR(t *testing.T) {
|
||||||
require.Equal(t, opcode.RET, opCode)
|
require.Equal(t, opcode.RET, opCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func alphaKeysSource() client.AlphabetKeys {
|
func alphaKeysSource() client.AlphabetKeys {
|
||||||
return func() (keys.PublicKeys, error) {
|
return func() (keys.PublicKeys, error) {
|
||||||
|
@ -382,19 +428,22 @@ func script(hash util.Uint160, method string, args ...interface{}) []byte {
|
||||||
return bw.Bytes()
|
return bw.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func correctNR(script []byte) *payload.P2PNotaryRequest {
|
func correctNR(script []byte, additionalWitness bool) *payload.P2PNotaryRequest {
|
||||||
alphaVerificationScript, _ := smartcontract.CreateMultiSigRedeemScript(len(alphaKeys)*2/3+1, alphaKeys)
|
alphaVerificationScript, _ := smartcontract.CreateMultiSigRedeemScript(len(alphaKeys)*2/3+1, alphaKeys)
|
||||||
|
|
||||||
return &payload.P2PNotaryRequest{
|
signers := []transaction.Signer{
|
||||||
MainTransaction: &transaction.Transaction{
|
|
||||||
Signers: []transaction.Signer{
|
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
Account: hash.Hash160(alphaVerificationScript),
|
Account: hash.Hash160(alphaVerificationScript),
|
||||||
},
|
},
|
||||||
{},
|
{},
|
||||||
},
|
}
|
||||||
Scripts: []transaction.Witness{
|
if additionalWitness { // insert on element with index 2
|
||||||
|
signers = append(signers[:2+1], signers[2:]...)
|
||||||
|
signers[2] = transaction.Signer{Account: hash.Hash160(alphaVerificationScript)}
|
||||||
|
}
|
||||||
|
|
||||||
|
scripts := []transaction.Witness{
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
InvocationScript: dummyInvocationScript,
|
InvocationScript: dummyInvocationScript,
|
||||||
|
@ -403,11 +452,28 @@ func correctNR(script []byte) *payload.P2PNotaryRequest {
|
||||||
{
|
{
|
||||||
InvocationScript: dummyInvocationScript,
|
InvocationScript: dummyInvocationScript,
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
|
if additionalWitness { // insert on element with index 2
|
||||||
|
scripts = append(scripts[:2+1], scripts[2:]...)
|
||||||
|
scripts[2] = transaction.Witness{
|
||||||
|
InvocationScript: dummyInvocationScript,
|
||||||
|
VerificationScript: alphaVerificationScript,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nKeys := uint8(len(alphaKeys))
|
||||||
|
if additionalWitness {
|
||||||
|
nKeys++
|
||||||
|
}
|
||||||
|
|
||||||
|
return &payload.P2PNotaryRequest{
|
||||||
|
MainTransaction: &transaction.Transaction{
|
||||||
|
Signers: signers,
|
||||||
|
Scripts: scripts,
|
||||||
Attributes: []transaction.Attribute{
|
Attributes: []transaction.Attribute{
|
||||||
{
|
{
|
||||||
Value: &transaction.NotaryAssisted{
|
Value: &transaction.NotaryAssisted{
|
||||||
NKeys: uint8(len(alphaKeys)),
|
NKeys: nKeys,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue