From fced6a27ba635d0afb47b32a886aa60a8e9e9423 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 21 Nov 2023 18:41:58 +0300 Subject: [PATCH] compiler: iterate over autoguessed events in reproducible way Otherwise it's undertermined which of two unnamed structures will get "Unnamed" and "UnnamedX" which can break the test from time to time. Signed-off-by: Roman Khimov --- .../notifications/rpcbindings_guessed.out | 26 +++++++++---------- pkg/compiler/compiler.go | 13 ++++++++-- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/cli/smartcontract/testdata/rpcbindings/notifications/rpcbindings_guessed.out b/cli/smartcontract/testdata/rpcbindings/notifications/rpcbindings_guessed.out index e940fa65e..f3cf84aee 100755 --- a/cli/smartcontract/testdata/rpcbindings/notifications/rpcbindings_guessed.out +++ b/cli/smartcontract/testdata/rpcbindings/notifications/rpcbindings_guessed.out @@ -20,12 +20,12 @@ var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xa // Unnamed is a contract-specific unnamed type used by its methods. type Unnamed struct { I *big.Int + B bool } // UnnamedX is a contract-specific unnamedX type used by its methods. type UnnamedX struct { I *big.Int - B bool } // ComplicatedNameEvent represents "! complicated name %$#" event emitted by the contract. @@ -40,7 +40,7 @@ type SomeMapEvent struct { // SomeStructEvent represents "SomeStruct" event emitted by the contract. type SomeStructEvent struct { - S *UnnamedX + S *Unnamed } // SomeArrayEvent represents "SomeArray" event emitted by the contract. @@ -50,7 +50,7 @@ type SomeArrayEvent struct { // SomeUnexportedFieldEvent represents "SomeUnexportedField" event emitted by the contract. type SomeUnexportedFieldEvent struct { - S *Unnamed + S *UnnamedX } // Actor is used by Contract to call state-changing methods. @@ -202,7 +202,7 @@ func (res *Unnamed) FromStackItem(item stackitem.Item) error { if !ok { return errors.New("not an array") } - if len(arr) != 1 { + if len(arr) != 2 { return errors.New("wrong number of structure elements") } @@ -216,6 +216,12 @@ func (res *Unnamed) FromStackItem(item stackitem.Item) error { return fmt.Errorf("field I: %w", err) } + index++ + res.B, err = arr[index].TryBool() + if err != nil { + return fmt.Errorf("field B: %w", err) + } + return nil } @@ -236,7 +242,7 @@ func (res *UnnamedX) FromStackItem(item stackitem.Item) error { if !ok { return errors.New("not an array") } - if len(arr) != 2 { + if len(arr) != 1 { return errors.New("wrong number of structure elements") } @@ -250,12 +256,6 @@ func (res *UnnamedX) FromStackItem(item stackitem.Item) error { return fmt.Errorf("field I: %w", err) } - index++ - res.B, err = arr[index].TryBool() - if err != nil { - return fmt.Errorf("field B: %w", err) - } - return nil } @@ -497,7 +497,7 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error { err error ) index++ - e.S, err = itemToUnnamedX(arr[index], nil) + e.S, err = itemToUnnamed(arr[index], nil) if err != nil { return fmt.Errorf("field S: %w", err) } @@ -627,7 +627,7 @@ func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error { err error ) index++ - e.S, err = itemToUnnamed(arr[index], nil) + e.S, err = itemToUnnamedX(arr[index], nil) if err != nil { return fmt.Errorf("field S: %w", err) } diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index d6bba8549..37c9077ec 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -11,6 +11,7 @@ import ( "io" "os" "path/filepath" + "sort" "strings" "github.com/nspcc-dev/neo-go/pkg/smartcontract" @@ -357,8 +358,16 @@ func CompileAndSave(src string, o *Options) ([]byte, error) { } if o.GuessEventTypes { if len(di.EmittedEvents) > 0 { - for eventName, eventUsages := range di.EmittedEvents { - var manifestEvent HybridEvent + var keys = make([]string, 0, len(di.EmittedEvents)) + for k := range di.EmittedEvents { + keys = append(keys, k) + } + sort.Strings(keys) + for _, eventName := range keys { + var ( + eventUsages = di.EmittedEvents[eventName] + manifestEvent HybridEvent + ) for _, e := range o.ContractEvents { if e.Name == eventName { manifestEvent = e