Skip to content

Commit

Permalink
fix export tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjbrettj committed Apr 10, 2023
1 parent 6e8c52e commit f50b1a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/runtime/wasmer/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package wasmer

import (
"bytes"
"errors"
"fmt"

"github.com/ChainSafe/gossamer/dot/types"
Expand All @@ -14,6 +15,8 @@ import (
"github.com/ChainSafe/gossamer/pkg/scale"
)

var errEmptyKeyOwnershipProof = errors.New("key ownership proof is nil")

// ValidateTransaction runs the extrinsic through the runtime function
// TaggedTransactionQueue_validate_transaction and returns *transaction.Validity. The error can
// be a VDT of either transaction.InvalidTransaction or transaction.UnknownTransaction, or can represent
Expand Down Expand Up @@ -116,8 +119,9 @@ func (in *Instance) BabeGenerateKeyOwnershipProof(slot uint64, authorityID [32]b
return nil, fmt.Errorf("scale decoding key ownership proof: %w", err)
}

// TODO check with team if returning error is preferred or should we keep just returning empty value
if keyOwnershipProof == nil {
return types.OpaqueKeyOwnershipProof{}, fmt.Errorf("key ownership proof is nil")
return types.OpaqueKeyOwnershipProof{}, fmt.Errorf("%w", errEmptyKeyOwnershipProof)
}

return *keyOwnershipProof, nil
Expand Down Expand Up @@ -309,7 +313,7 @@ func (in *Instance) GrandpaGenerateKeyOwnershipProof(authSetID uint64, authority
}

if keyOwnershipProof == nil {
return types.GrandpaOpaqueKeyOwnershipProof{}, fmt.Errorf("key ownership proof is nil")
return types.GrandpaOpaqueKeyOwnershipProof{}, fmt.Errorf("%w", errEmptyKeyOwnershipProof)
}

return *keyOwnershipProof, nil
Expand Down
5 changes: 2 additions & 3 deletions lib/runtime/wasmer/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package wasmer
import (
"bytes"
"encoding/json"
"fmt"
"github.com/centrifuge/go-substrate-rpc-client/v4/signature"
"math/big"
"os"
Expand Down Expand Up @@ -323,7 +322,7 @@ func TestInstance_BabeGenerateKeyOwnershipProof(t *testing.T) {

const slot = uint64(10)
_, err = rt.BabeGenerateKeyOwnershipProof(slot, authorityID)
require.NoError(t, err)
require.ErrorIs(t, err, errEmptyKeyOwnershipProof)
})
}
}
Expand Down Expand Up @@ -1117,7 +1116,7 @@ func TestInstance_GrandpaGenerateKeyOwnershipProof(t *testing.T) {

_, err := instance.GrandpaGenerateKeyOwnershipProof(uint64(0), authorityID)
// Since the input is not valid with respect to the instance, and empty proof is returned
require.ErrorIs(t, err, fmt.Errorf("key ownership proof is nil"))
require.ErrorIs(t, err, errEmptyKeyOwnershipProof)
}

func TestInstance_GrandpaSubmitReportEquivocationUnsignedExtrinsic(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions lib/runtime/wasmer/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,7 @@ func ext_offchain_submit_transaction_version_1(env interface{}, args []wasmer.Va
// validate the transaction
txv := transaction.NewValidity(0, [][]byte{{}}, [][]byte{{}}, 0, false)
vtx := transaction.NewValidTransaction(extrinsic, txv)

instanceContext.Transaction.AddToPool(vtx)

ptr, err := toWasmMemoryOptionalNil(instanceContext)
Expand Down

0 comments on commit f50b1a4

Please sign in to comment.