core: add ScriptFromWitness function
Extracting verification script from witness became a common task. This commit adds such a possibility.
This commit is contained in:
parent
9cc0fca9d2
commit
714c466c2c
2 changed files with 41 additions and 8 deletions
|
@ -4,7 +4,10 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/core/storage"
|
||||
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
||||
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
||||
"github.com/CityOfZion/neo-go/pkg/io"
|
||||
"github.com/CityOfZion/neo-go/pkg/util"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -65,6 +68,27 @@ func TestAddBlock(t *testing.T) {
|
|||
assert.Equal(t, lastBlock.Hash(), bc.CurrentHeaderHash())
|
||||
}
|
||||
|
||||
func TestScriptFromWitness(t *testing.T) {
|
||||
witness := &transaction.Witness{}
|
||||
h := util.Uint160{1, 2, 3}
|
||||
|
||||
res, err := ScriptFromWitness(h, witness)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, res)
|
||||
|
||||
witness.VerificationScript = []byte{4, 8, 15, 16, 23, 42}
|
||||
h = hash.Hash160(witness.VerificationScript)
|
||||
|
||||
res, err = ScriptFromWitness(h, witness)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, res)
|
||||
|
||||
h[0] = ^h[0]
|
||||
res, err = ScriptFromWitness(h, witness)
|
||||
require.Error(t, err)
|
||||
require.Nil(t, res)
|
||||
}
|
||||
|
||||
func TestGetHeader(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
block := newBlock(1, newMinerTX())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue