mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 19:29:39 +00:00
Merge pull request #2691 from nspcc-dev/sc-builder-len
smartcontract: add Len to Builder
This commit is contained in:
commit
8ecafaaadf
2 changed files with 30 additions and 0 deletions
|
@ -66,6 +66,13 @@ func (b *Builder) InvokeWithAssert(contract util.Uint160, method string, params
|
|||
b.Assert()
|
||||
}
|
||||
|
||||
// Len returns the current length of the script. It's useful to perform script
|
||||
// length checks (wrt transaction.MaxScriptLength limit) while building the
|
||||
// script.
|
||||
func (b *Builder) Len() int {
|
||||
return b.bw.Len()
|
||||
}
|
||||
|
||||
// Script return current script, you can't use Builder after invoking this method
|
||||
// unless you Reset it.
|
||||
func (b *Builder) Script() ([]byte, error) {
|
||||
|
|
23
pkg/smartcontract/builder_test.go
Normal file
23
pkg/smartcontract/builder_test.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package smartcontract
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBuilder(t *testing.T) {
|
||||
b := NewBuilder()
|
||||
require.Equal(t, 0, b.Len())
|
||||
b.InvokeMethod(util.Uint160{1, 2, 3}, "method")
|
||||
require.Equal(t, 37, b.Len())
|
||||
b.InvokeMethod(util.Uint160{1, 2, 3}, "transfer", util.Uint160{3, 2, 1}, util.Uint160{9, 8, 7}, 100500)
|
||||
require.Equal(t, 126, b.Len())
|
||||
s, err := b.Script()
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, s)
|
||||
require.Equal(t, 126, len(s))
|
||||
b.Reset()
|
||||
require.Equal(t, 0, b.Len())
|
||||
}
|
Loading…
Reference in a new issue