From d3a9179eac1c7d97f3eedfe22612cdfa12394e49 Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Wed, 24 Jul 2024 11:01:03 +0200 Subject: [PATCH] Drop source code locally --- .github/goreleaser.yaml | 8 -- .golangci.yaml | 88 +++++++++++++++++-- Dockerfile.release | 1 - Makefile | 10 +++ internal/batcher/batcher.go | 8 +- internal/client/client.go | 1 - internal/collector/collector.go | 8 +- internal/collector/types.go | 4 +- internal/config.go | 4 +- internal/distributor/distributor.go | 8 +- internal/output.go | 18 ++-- internal/pipeline.go | 4 +- internal/runtime/common_deployment.go | 66 -------------- internal/runtime/helper.go | 2 +- internal/runtime/helper_test.go | 2 +- internal/runtime/package_deployment.go | 68 ++++++++++++++ internal/runtime/realm_call.go | 33 +++---- internal/runtime/realm_deployment.go | 68 ++++++++++++++ internal/runtime/runtime.go | 17 ++-- internal/runtime/runtime_test.go | 27 ------ .../package.gno => internal/runtime/source.go | 25 ++++++ internal/testing/testing.go | 2 +- scripts/r/realm.gno | 13 --- 23 files changed, 300 insertions(+), 185 deletions(-) delete mode 100644 internal/runtime/common_deployment.go create mode 100644 internal/runtime/package_deployment.go create mode 100644 internal/runtime/realm_deployment.go rename scripts/p/package.gno => internal/runtime/source.go (61%) delete mode 100644 scripts/r/realm.gno diff --git a/.github/goreleaser.yaml b/.github/goreleaser.yaml index 889b86e..5bc33f3 100644 --- a/.github/goreleaser.yaml +++ b/.github/goreleaser.yaml @@ -60,8 +60,6 @@ dockers: - "--label=org.opencontainers.image.title={{.ProjectName}}" - "--label=org.opencontainers.image.revision={{.FullCommit}}" - "--label=org.opencontainers.image.version={{.Version}}" - extra_files: - - scripts - use: buildx dockerfile: Dockerfile.release goos: linux @@ -75,8 +73,6 @@ dockers: - "--label=org.opencontainers.image.title={{.ProjectName}}" - "--label=org.opencontainers.image.revision={{.FullCommit}}" - "--label=org.opencontainers.image.version={{.Version}}" - extra_files: - - scripts - use: buildx dockerfile: Dockerfile.release goos: linux @@ -91,8 +87,6 @@ dockers: - "--label=org.opencontainers.image.title={{.ProjectName}}" - "--label=org.opencontainers.image.revision={{.FullCommit}}" - "--label=org.opencontainers.image.version={{.Version}}" - extra_files: - - scripts - use: buildx dockerfile: Dockerfile.release goos: linux @@ -107,8 +101,6 @@ dockers: - "--label=org.opencontainers.image.title={{.ProjectName}}" - "--label=org.opencontainers.image.revision={{.FullCommit}}" - "--label=org.opencontainers.image.version={{.Version}}" - extra_files: - - scripts docker_manifests: # https://goreleaser.com/customization/docker_manifest/ diff --git a/.golangci.yaml b/.golangci.yaml index 03bb00d..00982e7 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,14 +1,62 @@ run: - timeout: 5m + concurrency: 8 + timeout: 10m + issue-exit-code: 1 tests: true skip-dirs-use-default: true + modules-download-mode: readonly + allow-parallel-runners: false + go: "" -service: - golangci-lint-version: latest +output: + uniq-by-line: false + path-prefix: "" + sort-results: true + +issues: + max-issues-per-linter: 0 + max-same-issues: 0 + new: false + fix: false + exclude-rules: + - path: (.+)_test.go + linters: + - nilnil + - gosec linters: + fast: false disable-all: true enable: + - asasalint # Check for pass []any as any in variadic func(...any) + - asciicheck # Detects funky ASCII characters + - bidichk # Checks for dangerous unicode character sequences + - durationcheck # Check for two durations multiplied together + - errcheck # Forces to not skip error check + - exportloopref # Checks for pointers to enclosing loop variables + - gocritic # Bundles different linting checks + - godot # Checks for periods at the end of comments + - gomoddirectives # Allow or ban replace directives in go.mod + - gosimple # Code simplification + - govet # Official Go tool + - ineffassign # Detects when assignments to existing variables are not used + - nakedret # Finds naked/bare returns and requires change them + - nilerr # Requires explicit returns + - nilnil # Requires explicit returns + - promlinter # Lints Prometheus metrics names + - reassign # Checks that package variables are not reassigned + - revive # Drop-in replacement for golint + - tenv # Detects using os.Setenv instead of t.Setenv + - testableexamples # Checks if examples are testable (have expected output) + - unparam # Finds unused params + - usestdlibvars # Detects the possibility to use variables/constants from stdlib + - wastedassign # Finds wasted assignment statements + - loggercheck # Checks the odd number of key and value pairs for common logger libraries + - nestif # Finds deeply nested if statements + - nonamedreturns # Reports all named returns + - decorder # Check declaration order of types, consts, vars and funcs + - gocheckcompilerdirectives # Checks that compiler directive comments (//go:) are valid + - gochecknoinits # Checks for init methods - whitespace # Tool for detection of leading and trailing whitespace - wsl # Forces you to use empty lines - unconvert # Unnecessary type conversions @@ -25,22 +73,44 @@ linters: - importas # Enforces consistent import aliases - gosec # Security problems - gofmt # Whether the code was gofmt-ed + - gofumpt # Stricter gofmt - goimports # Unused imports - goconst # Repeated strings that could be replaced by a constant - - forcetypeassert # Finds forced type assertions - dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f()) - - dupl # Code clone detection - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13 - unused # Checks Go code for unused constants, variables, functions and types -issues: - exclude-files: - - tools/tools.go - linters-settings: + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - hugeParam + - rangeExprCopy + - rangeValCopy + - importShadow + - unnamedResult + errcheck: + check-type-assertions: false + check-blank: true + exclude-functions: + - io/ioutil.ReadFile + - io.Copy(*bytes.Buffer) + - io.Copy(os.Stdout) + nakedret: + max-func-lines: 1 + govet: + enable-all: true gofmt: simplify: true goconst: min-len: 3 min-occurrences: 3 + godot: + scope: all + period: false diff --git a/Dockerfile.release b/Dockerfile.release index e786781..53f0093 100644 --- a/Dockerfile.release +++ b/Dockerfile.release @@ -1,4 +1,3 @@ FROM scratch -COPY scripts /scripts COPY supernova / ENTRYPOINT [ "/supernova" ] \ No newline at end of file diff --git a/Makefile b/Makefile index d735685..7780854 100644 --- a/Makefile +++ b/Makefile @@ -13,3 +13,13 @@ test: .PHONY: lint lint: $(golangci_lint) run --config .golangci.yaml + +.PHONY: gofumpt +gofumpt: + go install mvdan.cc/gofumpt@latest + gofumpt -l -w . + +.PHONY: fixalign +fixalign: + go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest + fieldalignment -fix $(filter-out $@,$(MAKECMDGOALS)) # the full package name (not path!) \ No newline at end of file diff --git a/internal/batcher/batcher.go b/internal/batcher/batcher.go index c03e39c..018f672 100644 --- a/internal/batcher/batcher.go +++ b/internal/batcher/batcher.go @@ -87,7 +87,7 @@ func prepareTransactions(txs []*std.Tx) ([][]byte, error) { marshalledTxs[index] = txBin - _ = bar.Add(1) + _ = bar.Add(1) //nolint:errcheck // No need to check } return marshalledTxs, nil @@ -117,7 +117,7 @@ func (b *Batcher) generateBatches(txs [][]byte, batchSize int) ([]common.Batch, readyBatches[index] = cliBatch - _ = bar.Add(1) + _ = bar.Add(1) //nolint:errcheck // No need to check } return readyBatches, nil @@ -142,7 +142,7 @@ func sendBatches(readyBatches []common.Batch) ([][]any, error) { batchResults[index] = batchResult - _ = bar.Add(1) + _ = bar.Add(1) //nolint:errcheck // No need to check } fmt.Printf("✅ Successfully sent %d batches\n", numBatches) @@ -184,7 +184,7 @@ func parseBatchResults(batchResults [][]any, numTx int) ([][]byte, error) { txHashes[index] = txResult.Hash index++ - _ = bar.Add(1) + _ = bar.Add(1) //nolint:errcheck // No need to check } } diff --git a/internal/client/client.go b/internal/client/client.go index e8771a6..4eb27ba 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -95,7 +95,6 @@ func (h *Client) GetAccount(address string) (*gnoland.GnoAccount, error) { fmt.Sprintf("auth/accounts/%s", address), []byte{}, ) - if err != nil { return nil, fmt.Errorf("unable to fetch account %s, %w", address, err) } diff --git a/internal/collector/collector.go b/internal/collector/collector.go index 0c257a2..7376592 100644 --- a/internal/collector/collector.go +++ b/internal/collector/collector.go @@ -9,9 +9,7 @@ import ( "github.com/schollz/progressbar/v3" ) -var ( - errTimeout = errors.New("collector timed out") -) +var errTimeout = errors.New("collector timed out") // Collector is the transaction / block stat // collector. @@ -86,7 +84,7 @@ func (c *Collector) GetRunResult( } processed += belong - _ = bar.Add(belong) + _ = bar.Add(belong) //nolint:errcheck // No need to check // Fetch the total gas used by transactions blockGasUsed, err := c.cli.GetBlockGasUsed(blockNum) @@ -159,7 +157,7 @@ func (t *txLookup) anyBelong(txs types.Txs) int { // calculateTPS calculates the TPS for the sequence func calculateTPS(startTime time.Time, totalTx int) float64 { - diff := time.Now().Sub(startTime).Seconds() + diff := time.Since(startTime).Seconds() return float64(totalTx) / diff } diff --git a/internal/collector/types.go b/internal/collector/types.go index da41d2d..642b3b5 100644 --- a/internal/collector/types.go +++ b/internal/collector/types.go @@ -15,14 +15,14 @@ type Client interface { // RunResult is the complete test-run result type RunResult struct { - AverageTPS float64 `json:"averageTPS"` Blocks []*BlockResult `json:"blocks"` + AverageTPS float64 `json:"averageTPS"` } // BlockResult is the single-block test run result type BlockResult struct { - Number int64 `json:"blockNumber"` Time time.Time `json:"created"` + Number int64 `json:"blockNumber"` Transactions int64 `json:"numTransactions"` GasUsed int64 `json:"gasUsed"` GasLimit int64 `json:"gasLimit"` diff --git a/internal/config.go b/internal/config.go index 1423bb6..224dac7 100644 --- a/internal/config.go +++ b/internal/config.go @@ -19,10 +19,10 @@ var ( var ( // httpRegex is used for verifying the cluster's JSON-RPC HTTP endpoint - httpRegex = regexp.MustCompile(`(https?://.*)(:(\d*)\/?(.*))?`) + httpRegex = regexp.MustCompile(`(https?://.*)(:(\d*)/?(.*))?`) // wsRegex is used for verifying the cluster's JSON-RPC WS endpoint - wsRegex = regexp.MustCompile(`(wss?://.*)(:(\d*)\/?(.*))?`) + wsRegex = regexp.MustCompile(`(wss?://.*)(:(\d*)/?(.*))?`) ) // Config is the central pipeline configuration diff --git a/internal/distributor/distributor.go b/internal/distributor/distributor.go index 8dca7af..4a0e759 100644 --- a/internal/distributor/distributor.go +++ b/internal/distributor/distributor.go @@ -14,9 +14,7 @@ import ( "github.com/schollz/progressbar/v3" ) -var ( - errInsufficientFunds = errors.New("insufficient distributor funds") -) +var errInsufficientFunds = errors.New("insufficient distributor funds") type Client interface { GetAccount(address string) (*gnoland.GnoAccount, error) @@ -89,8 +87,8 @@ func (d *Distributor) fundAccounts( chainID string, ) ([]std.Account, error) { type shortAccount struct { - address crypto.Address missingFunds std.Coin + address crypto.Address } var ( @@ -232,7 +230,7 @@ func (d *Distributor) fundAccounts( // Mark the account as funded readyAccounts = append(readyAccounts, nodeAccount) - _ = bar.Add(1) + _ = bar.Add(1) //nolint:errcheck // No need to check } fmt.Printf("✅ Successfully funded %d accounts\n", len(shortAccounts)) diff --git a/internal/output.go b/internal/output.go index f9bbcf9..9664657 100644 --- a/internal/output.go +++ b/internal/output.go @@ -14,21 +14,19 @@ func displayResults(result *collector.RunResult) { w := tabwriter.NewWriter(os.Stdout, 10, 20, 2, ' ', 0) // TPS // - _, _ = fmt.Fprintln(w, fmt.Sprintf("\nTPS: %.2f", result.AverageTPS)) + _, _ = fmt.Fprintf(w, "\nTPS: %.2f\n", result.AverageTPS) // Block info // _, _ = fmt.Fprintln(w, "\nBlock #\tGas Used\tGas Limit\tTransactions\tUtilization") for _, block := range result.Blocks { - _, _ = fmt.Fprintln( + _, _ = fmt.Fprintf( w, - fmt.Sprintf( - "Block #%d\t%d\t%d\t%d\t%.2f%%", - block.Number, - block.GasUsed, - block.GasLimit, - block.Transactions, - (float64(block.GasUsed)/float64(block.GasLimit))*100, - ), + "Block #%d\t%d\t%d\t%d\t%.2f%%\n", + block.Number, + block.GasUsed, + block.GasLimit, + block.Transactions, + (float64(block.GasUsed)/float64(block.GasLimit))*100, ) } diff --git a/internal/pipeline.go b/internal/pipeline.go index b648471..e358a79 100644 --- a/internal/pipeline.go +++ b/internal/pipeline.go @@ -152,7 +152,7 @@ func (p *Pipeline) initializeAccounts() []crypto.PrivKey { // Register the accounts with the keybase for i := 0; i < int(p.cfg.SubAccounts)+1; i++ { accounts[i] = signer.GenerateKeyFromSeed(seed, uint32(i)) - _ = bar.Add(1) + _ = bar.Add(1) //nolint:errcheck // No need to check } fmt.Printf("✅ Successfully generated %d accounts\n", len(accounts)) @@ -218,7 +218,7 @@ func prepareRuntime( return fmt.Errorf("unable to broadcast predeploy tx, %w", err) } - _ = bar.Add(1) + _ = bar.Add(1) //nolint:errcheck // No need to check } fmt.Printf("✅ Successfully predeployed %d transactions\n", len(predeployTxs)) diff --git a/internal/runtime/common_deployment.go b/internal/runtime/common_deployment.go deleted file mode 100644 index 6081261..0000000 --- a/internal/runtime/common_deployment.go +++ /dev/null @@ -1,66 +0,0 @@ -package runtime - -import ( - "fmt" - "path/filepath" - "time" - - "github.com/gnolang/gno/gno.land/pkg/sdk/vm" - "github.com/gnolang/gno/gnovm/pkg/gnolang" - "github.com/gnolang/gno/tm2/pkg/crypto" - "github.com/gnolang/gno/tm2/pkg/std" -) - -type commonDeployment struct { - deployDir string - deployPathPrefix string -} - -func newCommonDeployment(deployDir, deployPrefix string) *commonDeployment { - return &commonDeployment{ - deployDir: deployDir, - deployPathPrefix: deployPrefix, - } -} - -func (c *commonDeployment) Initialize(_ std.Account, _ crypto.PrivKey, _ string) ([]*std.Tx, error) { - // No extra setup needed for this runtime type - return nil, nil -} - -func (c *commonDeployment) ConstructTransactions( - keys []crypto.PrivKey, - accounts []std.Account, - transactions uint64, - chainID string, -) ([]*std.Tx, error) { - // Get absolute path to folder - deployPathAbs, err := filepath.Abs(c.deployDir) - if err != nil { - return nil, fmt.Errorf("unable to resolve absolute path, %w", err) - } - - var ( - timestamp = time.Now().Unix() - - getMsgFn = func(creator std.Account, index int) std.Msg { - memPkg := gnolang.ReadMemPackage( - deployPathAbs, - fmt.Sprintf("%s/stress_%d_%d", c.deployPathPrefix, timestamp, index), - ) - - return vm.MsgAddPackage{ - Creator: creator.GetAddress(), - Package: memPkg, - } - } - ) - - return constructTransactions( - keys, - accounts, - transactions, - chainID, - getMsgFn, - ) -} diff --git a/internal/runtime/helper.go b/internal/runtime/helper.go index 1651030..3e4da09 100644 --- a/internal/runtime/helper.go +++ b/internal/runtime/helper.go @@ -70,7 +70,7 @@ func constructTransactions( // Mark the transaction as ready txs[i] = tx - _ = bar.Add(1) + _ = bar.Add(1) //nolint:errcheck // No need to check } fmt.Printf("✅ Successfully constructed %d transactions\n", transactions) diff --git a/internal/runtime/helper_test.go b/internal/runtime/helper_test.go index b0e2f04..62dc553 100644 --- a/internal/runtime/helper_test.go +++ b/internal/runtime/helper_test.go @@ -44,7 +44,7 @@ func TestHelper_ConstructTransactions(t *testing.T) { transactions = uint64(100) msg = vm.MsgAddPackage{} - getMsgFn = func(creator std.Account, index int) std.Msg { + getMsgFn = func(_ std.Account, _ int) std.Msg { return msg } ) diff --git a/internal/runtime/package_deployment.go b/internal/runtime/package_deployment.go new file mode 100644 index 0000000..9e4da6e --- /dev/null +++ b/internal/runtime/package_deployment.go @@ -0,0 +1,68 @@ +package runtime + +import ( + "fmt" + "time" + + "github.com/gnolang/gno/gno.land/pkg/sdk/vm" + "github.com/gnolang/gno/tm2/pkg/crypto" + "github.com/gnolang/gno/tm2/pkg/std" +) + +type packageDeployment struct{} + +func newPackageDeployment() *packageDeployment { + return &packageDeployment{} +} + +func (c *packageDeployment) Initialize( + _ std.Account, + _ crypto.PrivKey, + _ string, +) ([]*std.Tx, error) { + // No extra setup needed for this runtime type + return nil, nil +} + +func (c *packageDeployment) ConstructTransactions( + keys []crypto.PrivKey, + accounts []std.Account, + transactions uint64, + chainID string, +) ([]*std.Tx, error) { + var ( + timestamp = time.Now().Unix() + + getMsgFn = func(creator std.Account, index int) std.Msg { + memPkg := &std.MemPackage{ + Name: packageName, + Path: fmt.Sprintf( + "%s/%s/stress_%d_%d", + packagePathPrefix, + creator.GetAddress().String(), + timestamp, + index, + ), + Files: []*std.MemFile{ + { + Name: packageFileName, + Body: packageBody, + }, + }, + } + + return vm.MsgAddPackage{ + Creator: creator.GetAddress(), + Package: memPkg, + } + } + ) + + return constructTransactions( + keys, + accounts, + transactions, + chainID, + getMsgFn, + ) +} diff --git a/internal/runtime/realm_call.go b/internal/runtime/realm_call.go index 2967913..fa579ae 100644 --- a/internal/runtime/realm_call.go +++ b/internal/runtime/realm_call.go @@ -2,19 +2,15 @@ package runtime import ( "fmt" - "path/filepath" "time" "github.com/gnolang/gno/gno.land/pkg/sdk/vm" - "github.com/gnolang/gno/gnovm/pkg/gnolang" "github.com/gnolang/gno/tm2/pkg/crypto" "github.com/gnolang/gno/tm2/pkg/std" "github.com/gnolang/supernova/internal/signer" ) -const ( - methodName = "SayHello" -) +const methodName = "SayHello" type realmCall struct { realmPath string @@ -25,23 +21,28 @@ func newRealmCall() *realmCall { } func (r *realmCall) Initialize(account std.Account, key crypto.PrivKey, chainID string) ([]*std.Tx, error) { - // Get absolute path to folder - deployPathAbs, err := filepath.Abs(realmLocation) - if err != nil { - return nil, fmt.Errorf("unable to resolve absolute path, %w", err) - } - // The Realm needs to be deployed before // it can be interacted with - r.realmPath = fmt.Sprintf("%s/stress_%d", realmPathPrefix, time.Now().Unix()) + r.realmPath = fmt.Sprintf( + "%s/%s/stress_%d", + realmPathPrefix, + account.GetAddress().String(), + time.Now().Unix(), + ) // Construct the transaction msg := vm.MsgAddPackage{ Creator: account.GetAddress(), - Package: gnolang.ReadMemPackage( - deployPathAbs, - r.realmPath, - ), + Package: &std.MemPackage{ + Name: packageName, + Path: r.realmPath, + Files: []*std.MemFile{ + { + Name: realmFileName, + Body: realmBody, + }, + }, + }, } tx := &std.Tx{ diff --git a/internal/runtime/realm_deployment.go b/internal/runtime/realm_deployment.go new file mode 100644 index 0000000..4af878b --- /dev/null +++ b/internal/runtime/realm_deployment.go @@ -0,0 +1,68 @@ +package runtime + +import ( + "fmt" + "time" + + "github.com/gnolang/gno/gno.land/pkg/sdk/vm" + "github.com/gnolang/gno/tm2/pkg/crypto" + "github.com/gnolang/gno/tm2/pkg/std" +) + +type realmDeployment struct{} + +func newRealmDeployment() *realmDeployment { + return &realmDeployment{} +} + +func (c *realmDeployment) Initialize( + _ std.Account, + _ crypto.PrivKey, + _ string, +) ([]*std.Tx, error) { + // No extra setup needed for this runtime type + return nil, nil +} + +func (c *realmDeployment) ConstructTransactions( + keys []crypto.PrivKey, + accounts []std.Account, + transactions uint64, + chainID string, +) ([]*std.Tx, error) { + var ( + timestamp = time.Now().Unix() + + getMsgFn = func(creator std.Account, index int) std.Msg { + memPkg := &std.MemPackage{ + Name: packageName, + Path: fmt.Sprintf( + "%s/%s/stress_%d_%d", + realmPathPrefix, + creator.GetAddress().String(), + timestamp, + index, + ), + Files: []*std.MemFile{ + { + Name: realmFileName, + Body: realmBody, + }, + }, + } + + return vm.MsgAddPackage{ + Creator: creator.GetAddress(), + Package: memPkg, + } + } + ) + + return constructTransactions( + keys, + accounts, + transactions, + chainID, + getMsgFn, + ) +} diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go index 3c6185c..2c85f03 100644 --- a/internal/runtime/runtime.go +++ b/internal/runtime/runtime.go @@ -7,16 +7,11 @@ import ( ) const ( - realmLocation = "./scripts/r" - packageLocation = "./scripts/p" - - realmPathPrefix = "gno.land/r/demo" - packagePathPrefix = "gno.land/p/demo" + realmPathPrefix = "gno.land/r" + packagePathPrefix = "gno.land/p" ) -var ( - defaultDeployTxFee = std.NewFee(165000, common.DefaultGasFee) -) +var defaultDeployTxFee = std.NewFee(500000, common.DefaultGasFee) // Runtime is the base interface for all runtime // implementations. @@ -25,7 +20,7 @@ var ( // and to predeploy (initialize) any infrastructure (package) type Runtime interface { // Initialize prepares any infrastructure transactions that are required - // to be executed before the stress test runs, if any. + // to be executed before the stress test runs, if any Initialize( account std.Account, key crypto.PrivKey, @@ -48,9 +43,9 @@ func GetRuntime(runtimeType Type) Runtime { case RealmCall: return newRealmCall() case RealmDeployment: - return newCommonDeployment(realmLocation, realmPathPrefix) + return newRealmDeployment() case PackageDeployment: - return newCommonDeployment(packageLocation, packagePathPrefix) + return newPackageDeployment() default: return nil } diff --git a/internal/runtime/runtime_test.go b/internal/runtime/runtime_test.go index a831ddc..b2fdd5b 100644 --- a/internal/runtime/runtime_test.go +++ b/internal/runtime/runtime_test.go @@ -1,9 +1,6 @@ package runtime import ( - "os" - "path" - "runtime" "testing" "github.com/gnolang/gno/gno.land/pkg/sdk/vm" @@ -37,30 +34,9 @@ func verifyDeployTxCommon(t *testing.T, tx *std.Tx, expectedPrefix string) { assert.Equal(t, tx.Fee, defaultDeployTxFee) } -// moveToRoot sets the current working -// test directory to the project root. -// This is used because of fixed .gno files in -// ./scripts -func moveToRoot(t *testing.T) { - t.Helper() - - _, filename, _, ok := runtime.Caller(0) - if !ok { - t.Fatal("unable to get caller information") - } - - dir := path.Join(path.Dir(filename), "../..") - if err := os.Chdir(dir); err != nil { - t.Fatalf("unable to change to root dir, %v", err) - } -} - func TestRuntime_CommonDeployment(t *testing.T) { t.Parallel() - // Change the working directory to root - moveToRoot(t) - testTable := []struct { name string mode Type @@ -120,9 +96,6 @@ func TestRuntime_CommonDeployment(t *testing.T) { func TestRuntime_RealmCall(t *testing.T) { t.Parallel() - // Change the working directory to root - moveToRoot(t) - var ( transactions = uint64(100) accounts = generateAccounts(11) diff --git a/scripts/p/package.gno b/internal/runtime/source.go similarity index 61% rename from scripts/p/package.gno rename to internal/runtime/source.go index fe08bdf..7baa117 100644 --- a/scripts/p/package.gno +++ b/internal/runtime/source.go @@ -1,5 +1,22 @@ package runtime +const ( + realmBody = `package runtime + +var greeting string + +func init() { + greeting = "Hello" +} + +// SayHello says hello to the specified name, using +// the saved greeting +func SayHello(name string) string { + return greeting + " " + name + "!" +} +` + packageBody = `package runtime + type Language string const ( @@ -31,3 +48,11 @@ func GetGreeting(language Language) string { return "Hello" } } +` +) + +const ( + packageName = "runtime" + realmFileName = "realm.gno" + packageFileName = "package.gno" +) diff --git a/internal/testing/testing.go b/internal/testing/testing.go index c1401e2..6bc07a0 100644 --- a/internal/testing/testing.go +++ b/internal/testing/testing.go @@ -19,7 +19,7 @@ func GenerateMnemonic(t *testing.T) string { } // Generate the actual mnemonic - mnemonic, err := bip39.NewMnemonic(entropySeed[:]) + mnemonic, err := bip39.NewMnemonic(entropySeed) if err != nil { t.Fatalf("unable to generate mnemonic, %v", err) } diff --git a/scripts/r/realm.gno b/scripts/r/realm.gno deleted file mode 100644 index 6b0ebca..0000000 --- a/scripts/r/realm.gno +++ /dev/null @@ -1,13 +0,0 @@ -package runtime - -var greeting string - -func init() { - greeting = "Hello" -} - -// SayHello says hello to the specified name, using -// the saved greeting -func SayHello(name string) string { - return greeting + " " + name + "!" -}