core/tests: refactor getting contract state
Get 2 contracts in pair which is useful everytime we need to test syscall with one contract calling the other. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
e654d22991
commit
f96c217aba
1 changed files with 20 additions and 17 deletions
|
@ -325,7 +325,8 @@ func TestBlockchainGetContractState(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTestContractState() *state.Contract {
|
// getTestContractState returns 2 contracts second of which is allowed to call the first.
|
||||||
|
func getTestContractState() (*state.Contract, *state.Contract) {
|
||||||
script := []byte{
|
script := []byte{
|
||||||
byte(opcode.ABORT), // abort if no offset was provided
|
byte(opcode.ABORT), // abort if no offset was provided
|
||||||
byte(opcode.ADD), byte(opcode.RET),
|
byte(opcode.ADD), byte(opcode.RET),
|
||||||
|
@ -371,11 +372,25 @@ func getTestContractState() *state.Contract {
|
||||||
ReturnType: smartcontract.IntegerType,
|
ReturnType: smartcontract.IntegerType,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return &state.Contract{
|
cs := &state.Contract{
|
||||||
Script: script,
|
Script: script,
|
||||||
Manifest: *m,
|
Manifest: *m,
|
||||||
ID: 42,
|
ID: 42,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currScript := []byte{byte(opcode.NOP)}
|
||||||
|
m = manifest.NewManifest(hash.Hash160(currScript))
|
||||||
|
perm := manifest.NewPermission(manifest.PermissionHash, h)
|
||||||
|
perm.Methods.Add("add")
|
||||||
|
perm.Methods.Add("drop")
|
||||||
|
perm.Methods.Add("add3")
|
||||||
|
m.Permissions = append(m.Permissions, *perm)
|
||||||
|
|
||||||
|
return cs, &state.Contract{
|
||||||
|
Script: currScript,
|
||||||
|
Manifest: *m,
|
||||||
|
ID: 123,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadScript(script []byte, args ...interface{}) *vm.VM {
|
func loadScript(script []byte, args ...interface{}) *vm.VM {
|
||||||
|
@ -392,24 +407,12 @@ func TestContractCall(t *testing.T) {
|
||||||
_, ic, bc := createVM(t)
|
_, ic, bc := createVM(t)
|
||||||
defer bc.Close()
|
defer bc.Close()
|
||||||
|
|
||||||
cs := getTestContractState()
|
cs, currCs := getTestContractState()
|
||||||
require.NoError(t, ic.DAO.PutContractState(cs))
|
require.NoError(t, ic.DAO.PutContractState(cs))
|
||||||
|
require.NoError(t, ic.DAO.PutContractState(currCs))
|
||||||
|
|
||||||
currScript := []byte{byte(opcode.NOP)}
|
currScript := currCs.Script
|
||||||
|
|
||||||
h := cs.Manifest.ABI.Hash
|
h := cs.Manifest.ABI.Hash
|
||||||
m := manifest.NewManifest(hash.Hash160(currScript))
|
|
||||||
perm := manifest.NewPermission(manifest.PermissionHash, h)
|
|
||||||
perm.Methods.Add("add")
|
|
||||||
perm.Methods.Add("drop")
|
|
||||||
perm.Methods.Add("add3")
|
|
||||||
m.Permissions = append(m.Permissions, *perm)
|
|
||||||
|
|
||||||
require.NoError(t, ic.DAO.PutContractState(&state.Contract{
|
|
||||||
Script: currScript,
|
|
||||||
Manifest: *m,
|
|
||||||
ID: 123,
|
|
||||||
}))
|
|
||||||
|
|
||||||
addArgs := stackitem.NewArray([]stackitem.Item{stackitem.Make(1), stackitem.Make(2)})
|
addArgs := stackitem.NewArray([]stackitem.Item{stackitem.Make(1), stackitem.Make(2)})
|
||||||
t.Run("Good", func(t *testing.T) {
|
t.Run("Good", func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue