Skip to content

Cannot deploy realm packages that import "testing" package in non-test source code #4706

@notJoon

Description

@notJoon

Description

There is an issue where realm packages cannot be deployed when the "testing" package is imported in regular source code (not test files).

For example, assume we created a test helper package as follows:

// PATH: r/testutils/logger.gno
package testutils

import "testing"

func PrintLog(t *testing.T, msg string) {
    t.Helper()
    println(msg)
}

When deploying this package, the following error occurs:

# Run chain
cd gno.land
make fclean && make start.gnoland

# Deploy package
gnokey maketx addpkg -pkgdir path/to/root/r/testutils -pkgpath gno.land/r/testuils -insecure-password-stdin=true -remote localhost:26657 -broadcast=true -chainid dev -gas-fee 100000000ugnot -gas-wanted 100000000

Output:

Enter password.
TX HASH:    
INFO:       vm.version=develop
--= Error =--
Data: invalid gno package; type check errors:
gno.land/r/testutils.gno:5:2: could not import testing (unknown import path "testing")
Msg Traces:
    0  /Users/notJoon/gno-core/tm2/pkg/errors/errors.go:28 - deliver transaction failed: log:msg:0,success:false,log:--= Error =--
Data: vm.TypeCheckError{abciError:vm.abciError{}, Errors:[]string{"gno.land/r/testutils.gno:5:2: could not import testing (unknown import path \"testing\")"}}
Msg Traces:
...

I believe this issue occurs because after the MemPackageType type was added, test files and regular source code are now clearly separated, and during the deployment process, there's a type mismatch with the expected type.

type MemPackageType string
const (
MPAnyAll MemPackageType = "MPAnyAll" // MPUserAll or MPStdlibAll.
MPAnyProd MemPackageType = "MPAnyProd" // MPUserProd or MPStdlibProd.
MPAnyTest MemPackageType = "MPAnyTest" // MPUserTest or MPStdlibTest.
MPAnyIntegration MemPackageType = "MPAnyIntegration" // MPUserIntegration or MPStdlibIntegration.
MPStdlibAll MemPackageType = "MPStdlibAll" // stdlibs only, all files.
MPStdlibProd MemPackageType = "MPStdlibProd" // stdlibs only, no tests/filetests
MPStdlibTest MemPackageType = "MPStdlibTest" // stdlibs only, w/ tests, w/o integration/filetests
MPStdlibIntegration MemPackageType = "MPStdlibIntegration" // stdlibs only, only integration tests.
MPUserAll MemPackageType = "MPUserAll" // no stdlibs, gno pkg path, w/ tests/filetests.
MPUserProd MemPackageType = "MPUserProd" // no stdlibs, gno pkg path, no tests/filetests.
MPUserTest MemPackageType = "MPUserTest" // no stdlibs, gno pkg path, w/ tests, w/o integration/filetests.
MPUserIntegration MemPackageType = "MPUserIntegration" // no stdlibs, only integration tests.
MPFiletests MemPackageType = "MPFiletests" // filetests only, regardless of file name (tests/files).
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions