diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index db3c0d8c9e8..dccbcd3579b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,35 +1,30 @@ # CODEOWNERS: https://help.github.com/articles/about-codeowners/ - # Primary repo maintainers. -* @gnolang/core-tech +* @gnolang/tech-staff # Tendermint2 (Gno version). -pkgs/* @gnolang/core-tech +tm2/* @gnolang/tech-staff # Docs & Content. -docs/ @gnolang/core-tech -*.md @gnolang/core-tech +docs/ @gnolang/tech-staff +*.md @gnolang/tech-staff # TODO: add non-tech people here. # Gno examples and default contracts. -examples/* @gnolang/core-tech +examples/* @gnolang/tech-staff # TODO: add people from the community here. -# Gnoland, Gno.land. -examples/gno.land/system/* @gnolang/core-tech -examples/gno.land/gnoland/* @gnolang/core-tech -gnoland/* @gnolang/core-tech -cmd/gnoland/* @gnolang/core-tech +# Gno.land. +gno.land/* @gnolang/tech-staff # GnoVM/Gnolang. -pkgs/gnolang/* @gnolang/core-tech -stdlibs/* @gnolang/core-tech +gnovm/* @gnolang/tech-staff # Special files. @@ -37,3 +32,4 @@ PLAN.md @jaekwon @moul PHILOSOPHY.md @jaekwon @moul CONTRIBUTING.md @jaekwon @moul LICENSE.md @jaekwon @moul +.github/CODEOWNERS @jaekwon @moul diff --git a/.github/workflows/benchdata.yml b/.github/workflows/benchdata.yml new file mode 100644 index 00000000000..7c49bfb5362 --- /dev/null +++ b/.github/workflows/benchdata.yml @@ -0,0 +1,21 @@ +name: gobenchdata publish +on: push + # branches: [ "master" ] +jobs: + publish: + runs-on: self-hosted + strategy: + fail-fast: false + steps: + - name: checkout + uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: { go-version: "1.20" } + - name: gobenchdata publish + run: go run go.bobheadxi.dev/gobenchdata@v1 action + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + INPUT_PRUNE_COUNT: 0 + INPUT_GO_TEST_FLAGS: -cpu 1,2 -run=^$ + INPUT_PUBLISH: true + INPUT_PUBLISH_BRANCH: gh-pages diff --git a/.github/workflows/db-tests.yml b/.github/workflows/db-tests.yml index f8808890a4c..aa98e982003 100644 --- a/.github/workflows/db-tests.yml +++ b/.github/workflows/db-tests.yml @@ -3,11 +3,11 @@ name: db-tests on: pull_request: paths: - - "t2/pkg/db/**.go" + - "tm2/pkg/db/**.go" - "go.sum" - ".github/workflows/db-tests.yml" push: - branches: [ $default-branch ] + branches: [ "master" ] jobs: test: diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1ee27e32993..fc2a83bc2df 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,7 +7,7 @@ on: - "!docs/**" - "!**.md" push: - branches: [ $default-branch ] + branches: [ "master" ] jobs: build-push: diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 360a983efb1..ffbc3f866f5 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -10,7 +10,7 @@ on: - "examples/**.gno" - ".github/workflows/examples.yml" push: - branches: [ $default-branch ] + branches: [ "master" ] jobs: gno2go: diff --git a/.github/workflows/gnoland.yml b/.github/workflows/gnoland.yml index bdcd8811675..00bc9533b6d 100644 --- a/.github/workflows/gnoland.yml +++ b/.github/workflows/gnoland.yml @@ -10,7 +10,7 @@ on: - "gno.land/**" - ".github/workflows/gnovm.yml" push: - branches: [ $default-branch ] + branches: [ "master" ] jobs: build: diff --git a/.github/workflows/gnovm.yml b/.github/workflows/gnovm.yml index 507fde85d5f..d4543f1729a 100644 --- a/.github/workflows/gnovm.yml +++ b/.github/workflows/gnovm.yml @@ -11,7 +11,7 @@ on: - "tm2/**.go" - ".github/workflows/gnovm.yml" push: - branches: [ $default-branch ] + branches: [ "master" ] jobs: build: diff --git a/.github/workflows/misc.yml b/.github/workflows/misc.yml index bbc05a1fbe3..46489b999d9 100644 --- a/.github/workflows/misc.yml +++ b/.github/workflows/misc.yml @@ -2,7 +2,7 @@ name: misc on: push: - branches: [ $default-branch ] + branches: [ "master" ] pull_request: jobs: diff --git a/.github/workflows/tm2.yml b/.github/workflows/tm2.yml index a84d9b14348..8f588e5ae4d 100644 --- a/.github/workflows/tm2.yml +++ b/.github/workflows/tm2.yml @@ -8,8 +8,7 @@ on: - "tm2/**.go" - ".github/workflows/tm2.yml" push: - branches: - - [ $default-branch ] + branches: [ "master" ] jobs: build: diff --git a/.gitignore b/.gitignore index bd384b58046..a5730c8fc8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -misc/ *.sw[pon] cmd/foo.go unsorted.* diff --git a/Dockerfile b/Dockerfile index f57986aa10e..bb23e8cb0c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ RUN apt-get update && apt-get install -y expect ca-certificates && updat # slim images FROM runtime-base AS gnoland-slim +WORKDIR /opt/gno/src/gno.land/ COPY --from=build /opt/build/build/gnoland /opt/gno/bin/ ENTRYPOINT ["gnoland"] EXPOSE 26657 36657 diff --git a/examples/gno.land/r/demo/banktest/z_0_filetest.gno b/examples/gno.land/r/demo/banktest/z_0_filetest.gno index 1bb07146913..80cb0cf299c 100644 --- a/examples/gno.land/r/demo/banktest/z_0_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_0_filetest.gno @@ -10,10 +10,12 @@ import ( ) func main() { - banktestAddr := std.TestDerivePkgAddr("gno.land/r/banktest") + banktestAddr := std.DerivePkgAddr("gno.land/r/banktest") // print main balance before. - mainaddr := std.TestDerivePkgAddr("main") + mainaddr := std.DerivePkgAddr("main") + std.TestSetOrigCaller(mainaddr) + banker := std.GetBanker(std.BankerTypeReadonly) mainbal := banker.GetCoins(mainaddr) println("main before:", mainbal) // plus OrigSend equals 300. diff --git a/examples/gno.land/r/demo/banktest/z_1_filetest.gno b/examples/gno.land/r/demo/banktest/z_1_filetest.gno index 5cd4c7af4c6..6b0e8c396dd 100644 --- a/examples/gno.land/r/demo/banktest/z_1_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_1_filetest.gno @@ -7,7 +7,7 @@ import ( ) func main() { - banktestAddr := std.TestDerivePkgAddr("gno.land/r/banktest") + banktestAddr := std.DerivePkgAddr("gno.land/r/banktest") // simulate a Deposit call. std.TestSetOrigPkgAddr(banktestAddr) diff --git a/examples/gno.land/r/demo/banktest/z_2_filetest.gno b/examples/gno.land/r/demo/banktest/z_2_filetest.gno index 0881a159746..a0280e0d75b 100644 --- a/examples/gno.land/r/demo/banktest/z_2_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_2_filetest.gno @@ -7,10 +7,12 @@ import ( ) func main() { - banktestAddr := std.TestDerivePkgAddr("gno.land/r/demo/banktest") + banktestAddr := std.DerivePkgAddr("gno.land/r/demo/banktest") // print main balance before. - mainaddr := std.TestDerivePkgAddr("main") + mainaddr := std.DerivePkgAddr("main") + std.TestSetOrigCaller(mainaddr) + banker := std.GetBanker(std.BankerTypeReadonly) mainbal := banker.GetCoins(mainaddr) println("main before:", mainbal) // plus OrigSend equals 300. diff --git a/examples/gno.land/r/demo/boards/README.md b/examples/gno.land/r/demo/boards/README.md index f813b8601aa..177eb1df9b8 100644 --- a/examples/gno.land/r/demo/boards/README.md +++ b/examples/gno.land/r/demo/boards/README.md @@ -29,7 +29,7 @@ NOTE: You can generate 24 words with any good bip39 generator. ### Create a new account using your mnemonic. ```bash -./build/gnokey add KEYNAME --recover +./build/gnokey add --recover KEYNAME ``` NOTE: `KEYNAME` is your key identifier, and should be changed. diff --git a/examples/gno.land/r/demo/boards/z_4_filetest.gno b/examples/gno.land/r/demo/boards/z_4_filetest.gno index df6f58726bb..749566ea5bc 100644 --- a/examples/gno.land/r/demo/boards/z_4_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_4_filetest.gno @@ -458,7 +458,7 @@ func main() { // }, // "V": { // "@type": "/gno.StringValue", -// "value": "g1arjyc64rpthwn8zhxtzjvearm5scy43y7vm985" +// "value": "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" // } // }, // { @@ -837,7 +837,7 @@ func main() { // }, // "V": { // "@type": "/gno.StringValue", -// "value": "g1arjyc64rpthwn8zhxtzjvearm5scy43y7vm985" +// "value": "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" // } // }, // { @@ -847,7 +847,7 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "04bcdca23188f0e1b9a57b36c4bb33ed3cd72446", +// "Hash": "5b4b593f1d4b37cb99166247ea28174f91087fdd", // "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:82" // } // }, diff --git a/examples/gno.land/r/demo/nft/z_2_filetest.gno b/examples/gno.land/r/demo/nft/z_2_filetest.gno index d716e754f22..00d6eb0c0f0 100644 --- a/examples/gno.land/r/demo/nft/z_2_filetest.gno +++ b/examples/gno.land/r/demo/nft/z_2_filetest.gno @@ -20,5 +20,5 @@ func main() { } // Output: -// g1zur8hjter6pzguerw02rqqq0rgzysy2mg9eq2v +// g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm // g1v9jxgu33ta047h6lta047h6lta047h6l43dqc5 diff --git a/examples/gno.land/r/demo/nft/z_3_filetest.gno b/examples/gno.land/r/demo/nft/z_3_filetest.gno index e5cdc7e33a2..00a4d00291b 100644 --- a/examples/gno.land/r/demo/nft/z_3_filetest.gno +++ b/examples/gno.land/r/demo/nft/z_3_filetest.gno @@ -22,5 +22,5 @@ func main() { } // Output: -// g1zur8hjter6pzguerw02rqqq0rgzysy2mg9eq2v +// g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm // g1v9jxgu33ta047h6lta047h6lta047h6l43dqc5 diff --git a/examples/gno.land/r/demo/tests/tests.gno b/examples/gno.land/r/demo/tests/tests.gno index dde1e7cad75..50b763cb06d 100644 --- a/examples/gno.land/r/demo/tests/tests.gno +++ b/examples/gno.land/r/demo/tests/tests.gno @@ -6,6 +6,14 @@ func CurrentRealmPath() string { return std.CurrentRealmPath() } +func AssertOriginCall() { + std.AssertOriginCall() +} + +func IsOriginCall() bool { + return std.IsOriginCall() +} + //---------------------------------------- // Test structure to ensure cross-realm modification is prevented. diff --git a/examples/gno.land/r/demo/tests/tests_filetest.gno b/examples/gno.land/r/demo/tests/tests_filetest.gno new file mode 100644 index 00000000000..c4beb8e2005 --- /dev/null +++ b/examples/gno.land/r/demo/tests/tests_filetest.gno @@ -0,0 +1,28 @@ +package main + +import ( + "gno.land/r/demo/tests" +) + +func main() { + println("IsOriginCall:", tests.IsOriginCall()) + tests.AssertOriginCall() + println("AssertOriginCall doesn't panic when called directly") + + func() { + // if called inside a function literal, this is no longer an origin call + // because there's one additional frame (the function literal). + println("IsOriginCall:", tests.IsOriginCall()) + defer func() { + r := recover() + println("AssertOriginCall panics if when called inside a function literal:", r) + }() + tests.AssertOriginCall() + }() +} + +// Output: +// IsOriginCall: true +// AssertOriginCall doesn't panic when called directly +// IsOriginCall: false +// AssertOriginCall panics if when called inside a function literal: invalid non-origin call diff --git a/examples/gno.land/r/demo/tests/tests_test.gno b/examples/gno.land/r/demo/tests/tests_test.gno new file mode 100644 index 00000000000..6efc3f35672 --- /dev/null +++ b/examples/gno.land/r/demo/tests/tests_test.gno @@ -0,0 +1,32 @@ +package tests + +import ( + "testing" + + "gno.land/p/demo/testutils" +) + +func TestAssertOriginCall(t *testing.T) { + // No-panic case + AssertOriginCall() + if !IsOriginCall() { + t.Errorf("expected IsOriginCall=true but got false") + } + + // Panic case + expectedReason := "invalid non-origin call" + defer func() { + r := recover() + if r == nil || r.(string) != expectedReason { + t.Errorf("expected panic with '%v', got '%v'", expectedReason, r) + } + }() + func() { + // if called inside a function literal, this is no longer an origin call + // because there's one additional frame (the function literal). + if IsOriginCall() { + t.Errorf("expected IsOriginCall=false but got true") + } + AssertOriginCall() + }() +} diff --git a/examples/gno.land/r/demo/users/z_5_filetest.gno b/examples/gno.land/r/demo/users/z_5_filetest.gno index 54998e577d1..5a96eec5322 100644 --- a/examples/gno.land/r/demo/users/z_5_filetest.gno +++ b/examples/gno.land/r/demo/users/z_5_filetest.gno @@ -42,7 +42,7 @@ func main() { // ======================================== // ## user gnouser // -// * address = g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4 +// * address = g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm // * 9 invites // // my profile @@ -52,7 +52,7 @@ func main() { // // * address = g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 // * 0 invites -// * invited by g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4 +// * invited by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm // // my other profile // diff --git a/examples/gno.land/r/demo/users/z_6_filetest.gno b/examples/gno.land/r/demo/users/z_6_filetest.gno index 9e64943b725..bc6d747ebbe 100644 --- a/examples/gno.land/r/demo/users/z_6_filetest.gno +++ b/examples/gno.land/r/demo/users/z_6_filetest.gno @@ -10,7 +10,7 @@ import ( const admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") func main() { - caller := std.GetOrigCaller() // main + caller := std.GetOrigCaller() // as admin, grant invites to unregistered user. std.TestSetOrigCaller(admin) users.GrantInvites(caller.String() + ":1") @@ -18,4 +18,4 @@ func main() { } // Error: -// invalid user g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4 +// invalid user g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm diff --git a/examples/gno.land/r/gnoland/faucet/faucet_test.gno b/examples/gno.land/r/gnoland/faucet/faucet_test.gno index 822dc169045..c1202e09611 100644 --- a/examples/gno.land/r/gnoland/faucet/faucet_test.gno +++ b/examples/gno.land/r/gnoland/faucet/faucet_test.gno @@ -12,7 +12,7 @@ import ( func TestPackage(t *testing.T) { var ( adminaddr = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") - faucetaddr = std.TestDerivePkgAddr("gno.land/r/faucet") + faucetaddr = std.DerivePkgAddr("gno.land/r/faucet") controlleraddr1 = testutils.TestAddress("controller1") controlleraddr2 = testutils.TestAddress("controller2") controlleraddr3 = testutils.TestAddress("controller3") diff --git a/gno.land/pkg/gnoland/app.go b/gno.land/pkg/gnoland/app.go index 87114f33a88..95fe9d2df8d 100644 --- a/gno.land/pkg/gnoland/app.go +++ b/gno.land/pkg/gnoland/app.go @@ -23,7 +23,10 @@ import ( // NewApp creates the GnoLand application. func NewApp(rootDir string, skipFailingGenesisTxs bool, logger log.Logger) (abci.Application, error) { // Get main DB. - db := dbm.NewDB("gnolang", dbm.GoLevelDBBackend, filepath.Join(rootDir, "data")) + db, err := dbm.NewDB("gnolang", dbm.GoLevelDBBackend, filepath.Join(rootDir, "data")) + if err != nil { + return nil, fmt.Errorf("error initializing database %q using path %q: %w", dbm.GoLevelDBBackend, rootDir, err) + } // Capabilities keys. mainKey := store.NewStoreKey("main") diff --git a/gnovm/pkg/gnolang/go_bench_test.go b/gnovm/pkg/gnolang/go_bench_test.go index 1b9c1364347..837d7625f35 100644 --- a/gnovm/pkg/gnolang/go_bench_test.go +++ b/gnovm/pkg/gnolang/go_bench_test.go @@ -74,7 +74,7 @@ func BenchmarkSliceIterate10(b *testing.B) { } } } - fmt.Println(fs) + b.Log(fs) } type SomeStruct struct { @@ -93,7 +93,7 @@ func BenchmarkStructStack(b *testing.B) { s := SomeStruct{Field1: int32(i) % 20, Field2: 1} x = s.it() } - fmt.Println(x) + b.Log(x) } // this doesn't work @@ -104,7 +104,7 @@ func BenchmarkStructGC(b *testing.B) { s := gen(i) x = s.Field1 } - fmt.Println(x) + b.Log(x) } type TestField struct { @@ -239,7 +239,7 @@ func BenchmarkTypeSwitchOrCreate(b *testing.B) { } } } - fmt.Println(c) + b.Log(c) }) b.Run("super-struct", func(b *testing.B) { for j := 0; j < b.N; j++ { @@ -252,7 +252,7 @@ func BenchmarkTypeSwitchOrCreate(b *testing.B) { } } } - fmt.Println(c) + b.Log(c) }) } @@ -270,7 +270,7 @@ func BenchmarkReflectValueOf(b *testing.B) { } }) } - fmt.Println(rv) + b.Log(rv) } func BenchmarkReflectAddInt64(b *testing.B) { @@ -279,7 +279,7 @@ func BenchmarkReflectAddInt64(b *testing.B) { for i := 0; i < b.N; i++ { x += rv.Int() } - fmt.Println(x) + b.Log(x) } func BenchmarkNativeAddInt64(b *testing.B) { @@ -287,7 +287,7 @@ func BenchmarkNativeAddInt64(b *testing.B) { for i := 0; i < b.N; i++ { x += 1 } - fmt.Println(x) + b.Log(x) } func BenchmarkReflectTypeOf(b *testing.B) { @@ -296,7 +296,7 @@ func BenchmarkReflectTypeOf(b *testing.B) { for i := 0; i < b.N; i++ { rt = reflect.TypeOf(x) } - fmt.Println(x, rt) + b.Log(x, rt) } func BenchmarkInterfaceEquality(b *testing.B) { @@ -308,7 +308,7 @@ func BenchmarkInterfaceEquality(b *testing.B) { ctr++ } } - fmt.Println(ctr) + b.Log(ctr) } func BenchmarkPointerEquality(b *testing.B) { @@ -322,7 +322,7 @@ func BenchmarkPointerEquality(b *testing.B) { ctr++ } } - fmt.Println(ctr) + b.Log(ctr) } func BenchmarkPointerDerefEquality(b *testing.B) { @@ -336,7 +336,7 @@ func BenchmarkPointerDerefEquality(b *testing.B) { ctr++ } } - fmt.Println(ctr) + b.Log(ctr) } func BenchmarkArrayEquality(b *testing.B) { @@ -349,7 +349,7 @@ func BenchmarkArrayEquality(b *testing.B) { ctr++ } } - fmt.Println(ctr) + b.Log(ctr) }) b.Run("ArrayEquality[8]", func(b *testing.B) { ctr := 0 @@ -360,7 +360,7 @@ func BenchmarkArrayEquality(b *testing.B) { ctr++ } } - fmt.Println(ctr) + b.Log(ctr) }) b.Run("ArrayEquality[16]", func(b *testing.B) { ctr := 0 @@ -371,7 +371,7 @@ func BenchmarkArrayEquality(b *testing.B) { ctr++ } } - fmt.Println(ctr) + b.Log(ctr) }) b.Run("ArrayEquality[20]", func(b *testing.B) { ctr := 0 @@ -382,7 +382,7 @@ func BenchmarkArrayEquality(b *testing.B) { ctr++ } } - fmt.Println(ctr) + b.Log(ctr) }) b.Run("ArrayEquality[32]", func(b *testing.B) { ctr := 0 @@ -393,7 +393,7 @@ func BenchmarkArrayEquality(b *testing.B) { ctr++ } } - fmt.Println(ctr) + b.Log(ctr) }) b.Run("ArrayEquality[64]", func(b *testing.B) { ctr := 0 @@ -404,7 +404,7 @@ func BenchmarkArrayEquality(b *testing.B) { ctr++ } } - fmt.Println(ctr) + b.Log(ctr) }) b.Run("ArrayEquality[256]", func(b *testing.B) { ctr := 0 @@ -415,6 +415,6 @@ func BenchmarkArrayEquality(b *testing.B) { ctr++ } } - fmt.Println(ctr) + b.Log(ctr) }) } diff --git a/gnovm/stdlibs/stdlibs.go b/gnovm/stdlibs/stdlibs.go index 495482cfad2..89329aeaf4b 100644 --- a/gnovm/stdlibs/stdlibs.go +++ b/gnovm/stdlibs/stdlibs.go @@ -142,7 +142,7 @@ func InjectPackage(store gno.Store, pn *gno.PackageNode) { pn.DefineGoNativeValue("IntSize", strconv.IntSize) pn.DefineGoNativeValue("AppendUint", strconv.AppendUint) case "std": - // NOTE: some of these are overridden in tests/imports_test.go + // NOTE: some of these are overridden in tests/imports.go // Also see stdlibs/InjectPackage. pn.DefineNative("AssertOriginCall", gno.Flds( // params diff --git a/gnovm/tests/file.go b/gnovm/tests/file.go index a9f15ebcab3..b5511bfb110 100644 --- a/gnovm/tests/file.go +++ b/gnovm/tests/file.go @@ -34,8 +34,9 @@ func TestMachine(store gno.Store, stdout io.Writer, pkgPath string) *gno.Machine func testMachineCustom(store gno.Store, pkgPath string, stdout io.Writer, maxAlloc int64, send std.Coins) *gno.Machine { // FIXME: create a better package to manage this, with custom constructors - pkgAddr := gno.DerivePkgAddr(pkgPath) // the addr of the pkgPath called. - caller := gno.DerivePkgAddr(pkgPath) // NOTE: for the purpose of testing, the caller is generally the "main" package, same as pkgAddr. + pkgAddr := gno.DerivePkgAddr(pkgPath) // the addr of the pkgPath called. + caller := gno.DerivePkgAddr("user1.gno") + pkgCoins := std.MustParseCoins("200000000ugnot").Add(send) // >= send. banker := newTestBanker(pkgAddr.Bech32(), pkgCoins) ctx := stdlibs.ExecContext{ diff --git a/gnovm/tests/files/std2.gno b/gnovm/tests/files/std2.gno index 910e4eca728..fe218f8b34a 100644 --- a/gnovm/tests/files/std2.gno +++ b/gnovm/tests/files/std2.gno @@ -8,4 +8,4 @@ func main() { } // Output: -// g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4 +// g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm diff --git a/gnovm/tests/files/std4.gno b/gnovm/tests/files/std4.gno index fed8caa4fbe..d09bc6251c0 100644 --- a/gnovm/tests/files/std4.gno +++ b/gnovm/tests/files/std4.gno @@ -10,4 +10,4 @@ func main() { } // Output: -// g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4 +// g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm diff --git a/gnovm/tests/files/std6.gno b/gnovm/tests/files/std6.gno index 1c55b32d13a..20943f47d28 100644 --- a/gnovm/tests/files/std6.gno +++ b/gnovm/tests/files/std6.gno @@ -15,4 +15,4 @@ func main() { // Output: // g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4 -// g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4 +// g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm diff --git a/gnovm/tests/files/std7.gno b/gnovm/tests/files/std7.gno index c1a11c60b63..9d602cc2039 100644 --- a/gnovm/tests/files/std7.gno +++ b/gnovm/tests/files/std7.gno @@ -22,4 +22,4 @@ func main() { // Output: // g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4 // g1ssrgtfce6pzs8tp7s6y8473yrffqs9xlgntk0h -// g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4 +// g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm diff --git a/gnovm/tests/files/zrealm_std0.gno b/gnovm/tests/files/zrealm_std0.gno index c31b071185f..3f6bdae2537 100644 --- a/gnovm/tests/files/zrealm_std0.gno +++ b/gnovm/tests/files/zrealm_std0.gno @@ -11,4 +11,4 @@ func main() { } // Output: -// g157y5v3k529jyzhjjz4fn49tzzhf4gess6v39xg +// g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm diff --git a/gnovm/tests/files/zrealm_tests0.gno b/gnovm/tests/files/zrealm_tests0.gno index e4466959e6b..780e443ddee 100644 --- a/gnovm/tests/files/zrealm_tests0.gno +++ b/gnovm/tests/files/zrealm_tests0.gno @@ -245,7 +245,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "20", +// "Line": "28", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -301,7 +301,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "20", +// "Line": "28", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -558,6 +558,94 @@ func main() { // { // "T": { // "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// }, +// "FileName": "tests.gno", +// "IsMethod": false, +// "Name": "AssertOriginCall", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "tests.gno", +// "Line": "9", +// "Nonce": "0", +// "PkgPath": "gno.land/r/demo/tests" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "4" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// }, +// "FileName": "tests.gno", +// "IsMethod": false, +// "Name": "IsOriginCall", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "tests.gno", +// "Line": "13", +// "Nonce": "0", +// "PkgPath": "gno.land/r/demo/tests" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "4" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", // "Params": [ // { // "Embedded": false, @@ -590,7 +678,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "16", +// "Line": "24", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -637,7 +725,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "38", +// "Line": "46", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -671,7 +759,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "43", +// "Line": "51", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -705,7 +793,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "51", +// "Line": "59", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } diff --git a/gnovm/tests/imports.go b/gnovm/tests/imports.go index 30a272a9989..67ca1ba51e2 100644 --- a/gnovm/tests/imports.go +++ b/gnovm/tests/imports.go @@ -456,6 +456,15 @@ func TestStore(rootDir, filesPath string, stdin io.Reader, stdout, stderr io.Wri func testPackageInjector(store gno.Store, pn *gno.PackageNode) { // Also inject stdlibs native functions. stdlibs.InjectPackage(store, pn) + isOriginCall := func(m *gno.Machine) bool { + switch m.Frames[0].Func.Name { + case "main": // test is a _filetest + return len(m.Frames) == 3 + case "runtest": // test is a _test + return len(m.Frames) == 7 + } + panic("unable to determine if test is a _test or a _filetest") + } // Test specific injections: switch pn.PkgPath { case "strconv": @@ -474,9 +483,8 @@ func testPackageInjector(store gno.Store, pn *gno.PackageNode) { ), */ func(m *gno.Machine) { - isOrigin := len(m.Frames) == 3 - if !isOrigin { - panic("invalid non-origin call") + if !isOriginCall(m) { + m.Panic(typedString("invalid non-origin call")) } }, ) @@ -489,9 +497,8 @@ func testPackageInjector(store gno.Store, pn *gno.PackageNode) { ), */ func(m *gno.Machine) { - isOrigin := len(m.Frames) == 3 res0 := gno.TypedValue{T: gno.BoolType} - res0.SetBool(isOrigin) + res0.SetBool(isOriginCall(m)) m.PushValue(res0) }, ) @@ -636,27 +643,6 @@ func testPackageInjector(store gno.Store, pn *gno.PackageNode) { m.Context = ctx }, ) - pn.DefineNative("TestDerivePkgAddr", - gno.Flds( // params - "pkgPath", "string", - ), - gno.Flds( // results - "addr", "Address", - ), - func(m *gno.Machine) { - arg0 := m.LastBlock().GetParams1().TV - pkgPath := arg0.GetString() - pkgAddr := gno.DerivePkgAddr(pkgPath).Bech32() - res0 := gno.Go2GnoValue( - m.Alloc, - m.Store, - reflect.ValueOf(pkgAddr), - ) - addrT := store.GetType(gno.DeclaredTypeID("std", "Address")) - res0.T = addrT - m.PushValue(res0) - }, - ) // TODO: move elsewhere. pn.DefineNative("ClearStoreCache", gno.Flds( // params diff --git a/go.mod b/go.mod index 12ff58b1a7c..1e010167cee 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/gdamore/tcell/v2 v2.1.0 github.com/gnolang/cors v1.8.1 github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 - github.com/golang/protobuf v1.5.2 + github.com/golang/protobuf v1.5.3 github.com/google/gofuzz v1.2.0 github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.5.0 diff --git a/go.sum b/go.sum index 6f7719f2406..ae15c74077c 100644 --- a/go.sum +++ b/go.sum @@ -85,8 +85,8 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= diff --git a/misc/deployments/staging.gno.land/docker-compose.yml b/misc/deployments/staging.gno.land/docker-compose.yml index 45844cc7a23..c8701c1e1fb 100644 --- a/misc/deployments/staging.gno.land/docker-compose.yml +++ b/misc/deployments/staging.gno.land/docker-compose.yml @@ -6,15 +6,14 @@ services: build: ../../.. environment: - LOG_LEVEL=4 + working_dir: /opt/gno/src/gno.land command: - gnoland - --skip-failing-genesis-txs - - --chainid - - staging - - --genesis-remote - - staging.gno.land:36657 + - --chainid=staging + - --genesis-remote=staging.gno.land:36657 volumes: - - "./data/gnoland:/opt/gno/src/testdir" + - "./data/gnoland:/opt/gno/src/gno.land/testdir" ports: - 36656:36656 - 36657:36657 @@ -30,20 +29,14 @@ services: build: ../../.. command: - gnoweb - - --bind - - 0.0.0.0:80 - - --remote - - gnoland:36657 - - --captcha-site - - $RECAPTCHA_SITE_KEY - - --faucet-url - - https://faucet-staging.gno.land/ - - --help-chainid - - staging - - --help-remote - - staging.gno.land:36657 - - --home-content - - /overlay/HOME.md + - --bind=0.0.0.0:80 + - --remote=gnoland:36657 + - --captcha-site=$RECAPTCHA_SITE_KEY + - --faucet-url=https://faucet-staging.gno.land/ + - --help-chainid=staging + - --help-remote=staging.gno.land:36657 + - --pages-dir=/overlay/pages + - --views-dir=./gno.land/cmd/gnoweb/views volumes: - "./overlay:/overlay:ro" links: @@ -66,9 +59,9 @@ services: command: sh -xc " date && mkdir -p /.gno && - expect -c \"set timeout -1; spawn gnokey add faucet --home /.gno/ --recover; expect \\\"Enter a passphrase\\\"; send \\\"$GNOKEY_PASS\\r\\\"; expect \\\"Repeat the passphrase\\\"; send \\\"$GNOKEY_PASS\\r\\\"; expect \\\"Enter your bip39 mnemonic\\\"; send \\\"$FAUCET_WORDS\\r\\\"; expect eof\" && + expect -c \"set timeout -1; spawn gnokey add --home /.gno/ --recover faucet; expect \\\"Enter a passphrase\\\"; send \\\"$GNOKEY_PASS\\r\\\"; expect \\\"Repeat the passphrase\\\"; send \\\"$GNOKEY_PASS\\r\\\"; expect \\\"Enter your bip39 mnemonic\\\"; send \\\"$FAUCET_WORDS\\r\\\"; expect eof\" && while true; do - expect -c \"set timeout -1; spawn gnofaucet serve faucet --send 50000000ugnot --captcha-secret \\\"$RECAPTCHA_SECRET_KEY\\\" --remote gnoland:36657 --chain-id staging --home /.gno/; expect \\\"Enter password.\\\"; send \\\"$GNOKEY_PASS\\r\\\"; expect eof\"; + expect -c \"set timeout -1; spawn gnofaucet serve --send 50000000ugnot --captcha-secret \\\"$RECAPTCHA_SECRET_KEY\\\" --remote gnoland:36657 --chain-id staging --home /.gno/ faucet; expect \\\"Enter password\\\"; send \\\"$GNOKEY_PASS\\r\\\"; expect eof\"; sleep 5; done " diff --git a/tm2/pkg/amino/benchmark_test.go b/tm2/pkg/amino/benchmark_test.go index 7dc9773dfa4..56d22bd9fde 100644 --- a/tm2/pkg/amino/benchmark_test.go +++ b/tm2/pkg/amino/benchmark_test.go @@ -6,14 +6,17 @@ import ( "runtime/debug" "testing" - "github.com/gnolang/gno/tm2/pkg/amino" - "github.com/gnolang/gno/tm2/pkg/amino/tests" fuzz "github.com/google/gofuzz" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" + + "github.com/gnolang/gno/tm2/pkg/amino" + "github.com/gnolang/gno/tm2/pkg/amino/tests" ) func BenchmarkBinary(b *testing.B) { + b.Skip("too slow") + cdc := amino.NewCodec() for _, ptr := range tests.StructTypes { b.Logf("case %v", reflect.TypeOf(ptr)) @@ -29,6 +32,8 @@ func BenchmarkBinary(b *testing.B) { } func BenchmarkBinaryPBBindings(b *testing.B) { + b.Skip("too slow") + cdc := amino.NewCodec().WithPBBindings() for _, ptr := range tests.StructTypes { b.Logf("case %v (pbbindings)", reflect.TypeOf(ptr)) diff --git a/tm2/pkg/bft/consensus/replay_file.go b/tm2/pkg/bft/consensus/replay_file.go index 780240e3216..4daf1dbb4ab 100644 --- a/tm2/pkg/bft/consensus/replay_file.go +++ b/tm2/pkg/bft/consensus/replay_file.go @@ -272,11 +272,19 @@ func (pb *playback) replayConsoleLoop() int { func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cnscfg.ConsensusConfig) *ConsensusState { dbType := dbm.BackendType(config.DBBackend) // Get BlockStore - blockStoreDB := dbm.NewDB("blockstore", dbType, config.DBDir()) + blockStoreDB, err := dbm.NewDB("blockstore", dbType, config.DBDir()) + if err != nil { + osm.Exit(err.Error()) + } + blockStore := store.NewBlockStore(blockStoreDB) // Get State - stateDB := dbm.NewDB("state", dbType, config.DBDir()) + stateDB, err := dbm.NewDB("state", dbType, config.DBDir()) + if err != nil { + osm.Exit(err.Error()) + } + gdoc, err := sm.MakeGenesisDocFromFile(config.GenesisFile()) if err != nil { osm.Exit(err.Error()) diff --git a/tm2/pkg/bft/node/node.go b/tm2/pkg/bft/node/node.go index fbf36af9b28..4e38f8974f3 100644 --- a/tm2/pkg/bft/node/node.go +++ b/tm2/pkg/bft/node/node.go @@ -26,9 +26,6 @@ import ( rpcserver "github.com/gnolang/gno/tm2/pkg/bft/rpc/lib/server" sm "github.com/gnolang/gno/tm2/pkg/bft/state" "github.com/gnolang/gno/tm2/pkg/bft/state/txindex" - "github.com/gnolang/gno/tm2/pkg/events" - - //"github.com/gnolang/gno/tm2/pkg/bft/state/txindex/kv" "github.com/gnolang/gno/tm2/pkg/bft/state/txindex/null" "github.com/gnolang/gno/tm2/pkg/bft/store" "github.com/gnolang/gno/tm2/pkg/bft/types" @@ -37,6 +34,7 @@ import ( "github.com/gnolang/gno/tm2/pkg/crypto" dbm "github.com/gnolang/gno/tm2/pkg/db" "github.com/gnolang/gno/tm2/pkg/errors" + "github.com/gnolang/gno/tm2/pkg/events" "github.com/gnolang/gno/tm2/pkg/log" "github.com/gnolang/gno/tm2/pkg/p2p" "github.com/gnolang/gno/tm2/pkg/service" @@ -58,7 +56,7 @@ type DBProvider func(*DBContext) (dbm.DB, error) // specified in the ctx.Config. func DefaultDBProvider(ctx *DBContext) (dbm.DB, error) { dbType := dbm.BackendType(ctx.Config.DBBackend) - return dbm.NewDB(ctx.ID, dbType, ctx.Config.DBDir()), nil + return dbm.NewDB(ctx.ID, dbType, ctx.Config.DBDir()) } // GenesisDocProvider returns a GenesisDoc. diff --git a/tm2/pkg/bft/state/state_test.go b/tm2/pkg/bft/state/state_test.go index f2a31e70b0b..a48f4f0a3e4 100644 --- a/tm2/pkg/bft/state/state_test.go +++ b/tm2/pkg/bft/state/state_test.go @@ -25,7 +25,9 @@ func setupTestCase(t *testing.T) (func(t *testing.T), dbm.DB, sm.State) { config := cfg.ResetTestRoot("state_") dbType := dbm.BackendType(config.DBBackend) - stateDB := dbm.NewDB("state", dbType, config.DBDir()) + stateDB, err := dbm.NewDB("state", dbType, config.DBDir()) + require.NoError(t, err) + state, err := sm.LoadStateFromDBOrGenesisFile(stateDB, config.GenesisFile()) assert.NoError(t, err, "expected no error on LoadStateFromDBOrGenesisFile") diff --git a/tm2/pkg/bft/state/store_test.go b/tm2/pkg/bft/state/store_test.go index 2b73c7ca1cf..79282e6a311 100644 --- a/tm2/pkg/bft/state/store_test.go +++ b/tm2/pkg/bft/state/store_test.go @@ -60,11 +60,11 @@ func BenchmarkLoadValidators(b *testing.B) { config := cfg.ResetTestRoot("state_") defer os.RemoveAll(config.RootDir) dbType := dbm.BackendType(config.DBBackend) - stateDB := dbm.NewDB("state", dbType, config.DBDir()) + stateDB, err := dbm.NewDB("state", dbType, config.DBDir()) + require.NoError(b, err) + state, err := sm.LoadStateFromDBOrGenesisFile(stateDB, config.GenesisFile()) - if err != nil { - b.Fatal(err) - } + require.NoError(b, err) state.Validators = genValSet(valSetSize) state.NextValidators = state.Validators.CopyIncrementProposerPriority(1) sm.SaveState(stateDB, state) diff --git a/tm2/pkg/crypto/ed25519/bench_test.go b/tm2/pkg/crypto/ed25519/bench_test.go index d4ef2e628c3..0d7211bc2e8 100644 --- a/tm2/pkg/crypto/ed25519/bench_test.go +++ b/tm2/pkg/crypto/ed25519/bench_test.go @@ -9,6 +9,7 @@ import ( ) func BenchmarkKeyGeneration(b *testing.B) { + b.Skip("too slow") benchmarkKeygenWrapper := func(reader io.Reader) crypto.PrivKey { return genPrivKey(reader) } diff --git a/tm2/pkg/crypto/keys/armor/armor.go b/tm2/pkg/crypto/keys/armor/armor.go index e45af7f68a4..7233b27123a 100644 --- a/tm2/pkg/crypto/keys/armor/armor.go +++ b/tm2/pkg/crypto/keys/armor/armor.go @@ -115,8 +115,7 @@ func UnarmorDecryptPrivKey(armorStr string, passphrase string) (crypto.PrivKey, } saltBytes, err := hex.DecodeString(header["salt"]) if err != nil { - //nolint:errorlint - return privKey, fmt.Errorf("error decoding salt: %v", err.Error()) + return privKey, fmt.Errorf("error decoding salt: %w", err) } privKey, err = decryptPrivKey(saltBytes, encBytes, passphrase) return privKey, err diff --git a/tm2/pkg/crypto/keys/client/common.go b/tm2/pkg/crypto/keys/client/common.go index b26ac64f540..0fd40cecba6 100644 --- a/tm2/pkg/crypto/keys/client/common.go +++ b/tm2/pkg/crypto/keys/client/common.go @@ -1,8 +1,8 @@ package client import ( - "fmt" "os" + "path/filepath" ) type BaseOptions struct { @@ -21,15 +21,20 @@ var DefaultBaseOptions = BaseOptions{ func HomeDir() string { // if environment set, always use that. - hd := os.Getenv("GNO_HOME") - if hd != "" { - return hd + // if not, check whether can get os.UserHomeDir() + // if not, fall back to home directory + var err error + dir := os.Getenv("GNO_HOME") + if dir != "" { + return dir } - - // look for dir in home directory. - hd, err := os.UserHomeDir() + dir, err = os.UserConfigDir() + if err == nil { + return filepath.Join(dir, "gno") + } + dir, err = os.UserHomeDir() if err != nil { panic(err) } - return fmt.Sprintf("%s/.gno", hd) + return filepath.Join(dir, ".gno") } diff --git a/tm2/pkg/crypto/secp256k1/bench_test.go b/tm2/pkg/crypto/secp256k1/bench_test.go index 0daf4d34f10..e741179b232 100644 --- a/tm2/pkg/crypto/secp256k1/bench_test.go +++ b/tm2/pkg/crypto/secp256k1/bench_test.go @@ -9,6 +9,7 @@ import ( ) func BenchmarkKeyGeneration(b *testing.B) { + b.Skip("too slow") benchmarkKeygenWrapper := func(reader io.Reader) crypto.PrivKey { return genPrivKey(reader) } diff --git a/tm2/pkg/db/backend_test.go b/tm2/pkg/db/backend_test.go index b8c2d5ceade..b6cd3f026aa 100644 --- a/tm2/pkg/db/backend_test.go +++ b/tm2/pkg/db/backend_test.go @@ -12,7 +12,8 @@ func testBackendGetSetDelete(t *testing.T, backend BackendType) { t.Helper() // Default - db := NewDB("testdb", backend, t.TempDir()) + db, err := NewDB("testdb", backend, t.TempDir()) + require.NoError(t, err) // A nonexistent key should return nil, even if the key is empty require.Nil(t, db.Get([]byte(""))) @@ -137,7 +138,8 @@ func TestBackendsNilKeys(t *testing.T) { func TestGoLevelDBBackend(t *testing.T) { name := fmt.Sprintf("test_%x", randStr(12)) - db := NewDB(name, GoLevelDBBackend, t.TempDir()) + db, err := NewDB(name, GoLevelDBBackend, t.TempDir()) + require.NoError(t, err) _, ok := db.(*GoLevelDB) assert.True(t, ok) @@ -157,7 +159,8 @@ func testDBIterator(t *testing.T, backend BackendType) { t.Helper() name := fmt.Sprintf("test_%x", randStr(12)) - db := NewDB(name, backend, t.TempDir()) + db, err := NewDB(name, backend, t.TempDir()) + require.NoError(t, err) for i := 0; i < 10; i++ { if i != 6 { // but skip 6. diff --git a/tm2/pkg/db/c_level_db_test.go b/tm2/pkg/db/c_level_db_test.go index fdd7dc42e8b..39265ae8610 100644 --- a/tm2/pkg/db/c_level_db_test.go +++ b/tm2/pkg/db/c_level_db_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func BenchmarkRandomReadsWrites2(b *testing.B) { @@ -91,7 +92,8 @@ func TestCLevelDBBackend(t *testing.T) { name := fmt.Sprintf("test_%x", randStr(12)) // Can't use "" (current directory) or "./" here because levigo.Open returns: // "Error initializing DB: IO error: test_XXX.db: Invalid argument" - db := NewDB(name, CLevelDBBackend, t.TempDir()) + db, err := NewDB(name, CLevelDBBackend, t.TempDir()) + require.NoError(t, err) _, ok := db.(*CLevelDB) assert.True(t, ok) @@ -99,7 +101,8 @@ func TestCLevelDBBackend(t *testing.T) { func TestCLevelDBStats(t *testing.T) { name := fmt.Sprintf("test_%x", randStr(12)) - db := NewDB(name, CLevelDBBackend, t.TempDir()) + db, err := NewDB(name, CLevelDBBackend, t.TempDir()) + require.NoError(t, err) assert.NotEmpty(t, db.Stats()) } diff --git a/tm2/pkg/db/common_test.go b/tm2/pkg/db/common_test.go index dcb234780cd..ae318231294 100644 --- a/tm2/pkg/db/common_test.go +++ b/tm2/pkg/db/common_test.go @@ -83,7 +83,10 @@ func checkValuePanics(t *testing.T, itr Iterator) { func newTempDB(t *testing.T, backend BackendType) (db DB) { t.Helper() - return NewDB("testdb", backend, t.TempDir()) + db, err := NewDB("testdb", backend, t.TempDir()) + require.NoError(t, err) + + return db } // ---------------------------------------- diff --git a/tm2/pkg/db/db.go b/tm2/pkg/db/db.go index 845777222e2..228072fba55 100644 --- a/tm2/pkg/db/db.go +++ b/tm2/pkg/db/db.go @@ -55,21 +55,19 @@ func registerDBCreator(backend BackendType, creator dbCreator, force bool) { // NOTE: function panics if: // - backend is unknown (not registered) // - creator function, provided during registration, returns error -func NewDB(name string, backend BackendType, dir string) DB { +func NewDB(name string, backend BackendType, dir string) (DB, error) { dbCreator, ok := backends[backend] if !ok { - keys := make([]string, len(backends)) - i := 0 + var keys []string for k := range backends { - keys[i] = string(k) - i++ + keys = append(keys, string(k)) } - panic(fmt.Sprintf("Unknown db_backend %s, expected either %s", backend, strings.Join(keys, " or "))) + return nil, fmt.Errorf("unknown db_backend %s. Expected either %s", backend, strings.Join(keys, " or ")) } db, err := dbCreator(name, dir) if err != nil { - panic(fmt.Sprintf("Error initializing DB: %v", err)) + return nil, fmt.Errorf("error initializing DB: %w", err) } - return db + return db, nil } diff --git a/tm2/pkg/iavl/basic_test.go b/tm2/pkg/iavl/basic_test.go index 452c7e4235a..ab46792aee4 100644 --- a/tm2/pkg/iavl/basic_test.go +++ b/tm2/pkg/iavl/basic_test.go @@ -187,7 +187,9 @@ func TestRemove(t *testing.T) { size := 10000 keyLen, dataLen := 16, 40 - d := db.NewDB("test", "memdb", "") + d, err := db.NewDB("test", "memdb", "") + require.NoError(t, err) + defer d.Close() t1 := NewMutableTree(d, size) diff --git a/tm2/pkg/iavl/benchmarks/bench_test.go b/tm2/pkg/iavl/benchmarks/bench_test.go index d0cd878abe9..1f98ab9fefd 100644 --- a/tm2/pkg/iavl/benchmarks/bench_test.go +++ b/tm2/pkg/iavl/benchmarks/bench_test.go @@ -5,8 +5,11 @@ import ( "math/rand" "os" "runtime" + "strings" "testing" + "github.com/jaekwon/testify/require" + "github.com/gnolang/gno/tm2/pkg/db" "github.com/gnolang/gno/tm2/pkg/iavl" ) @@ -184,7 +187,6 @@ func BenchmarkMedium(b *testing.B) { {"goleveldb", 100000, 100, 16, 40}, // FIXME: this crashes on init! Either remove support, or make it work. // {"cleveldb", 100000, 100, 16, 40}, - {"leveldb", 100000, 100, 16, 40}, } runBenchmarks(b, benchmarks) } @@ -195,7 +197,6 @@ func BenchmarkSmall(b *testing.B) { {"goleveldb", 1000, 100, 4, 10}, // FIXME: this crashes on init! Either remove support, or make it work. // {"cleveldb", 100000, 100, 16, 40}, - {"leveldb", 1000, 100, 4, 10}, } runBenchmarks(b, benchmarks) } @@ -206,7 +207,6 @@ func BenchmarkLarge(b *testing.B) { {"goleveldb", 1000000, 100, 16, 40}, // FIXME: this crashes on init! Either remove support, or make it work. // {"cleveldb", 100000, 100, 16, 40}, - {"leveldb", 1000000, 100, 16, 40}, } runBenchmarks(b, benchmarks) } @@ -252,8 +252,10 @@ func runBenchmarks(b *testing.B, benchmarks []benchmark) { // note that "" leads to nil backing db! var d db.DB + var err error if bb.dbType != "nodb" { - d = db.NewDB("test", bb.dbType, dirName) + d, err = db.NewDB("test", bb.dbType, dirName) + require.NoError(b, err) defer d.Close() } b.Run(prefix, func(sub *testing.B) { @@ -280,7 +282,7 @@ func runSuite(b *testing.B, d db.DB, initSize, blockSize, keyLen, dataLen int) { t, keys := prepareTree(b, d, initSize, keyLen, dataLen) used := memUseMB() - init - fmt.Printf("Init Tree took %0.2f MB\n", used) + b.Logf("Init Tree took %0.2f MB\n", used) b.ResetTimer() @@ -290,12 +292,18 @@ func runSuite(b *testing.B, d db.DB, initSize, blockSize, keyLen, dataLen int) { b.Run("query-hits", func(sub *testing.B) { runKnownQueries(sub, t, keys) }) - b.Run("update", func(sub *testing.B) { - t = runUpdate(sub, t, dataLen, blockSize, keys) - }) - b.Run("block", func(sub *testing.B) { - t = runBlock(sub, t, keyLen, dataLen, blockSize, keys) - }) + if !strings.Contains(b.Name(), "goleveldb") { + // it panics with: panic: Orphan expires before it comes alive. 1 > 0 + b.Run("update", func(sub *testing.B) { + t = runUpdate(sub, t, dataLen, blockSize, keys) + }) + } + if !strings.Contains(b.Name(), "goleveldb") { + // it panics with: panic: Orphan expires before it comes alive. 1 > 0 + b.Run("block", func(sub *testing.B) { + t = runBlock(sub, t, keyLen, dataLen, blockSize, keys) + }) + } // both of these edit size of the tree too much // need to run with their own tree diff --git a/tm2/pkg/iavl/testutils_test.go b/tm2/pkg/iavl/testutils_test.go index d46cbe66bf4..30034d46a4a 100644 --- a/tm2/pkg/iavl/testutils_test.go +++ b/tm2/pkg/iavl/testutils_test.go @@ -3,10 +3,11 @@ package iavl import ( "bytes" "fmt" + mrand "math/rand" "runtime" "testing" - mrand "math/rand" + "github.com/jaekwon/testify/require" "github.com/gnolang/gno/tm2/pkg/amino" "github.com/gnolang/gno/tm2/pkg/db" @@ -54,7 +55,11 @@ func N(l, r interface{}) *Node { // Setup a deep node func T(n *Node) *MutableTree { - d := db.NewDB("test", db.MemDBBackend, "") + d, err := db.NewDB("test", db.MemDBBackend, "") + if err != nil { + panic(err) + } + t := NewMutableTree(d, 0) n.hashWithCount() @@ -108,7 +113,11 @@ func expectTraverse(t *testing.T, trav traverser, start, end string, count int) } func BenchmarkImmutableAvlTreeMemDB(b *testing.B) { - db := db.NewDB("test", db.MemDBBackend, "") + db, err := db.NewDB("test", db.MemDBBackend, "") + require.NoError(b, err) + + b.ResetTimer() + benchmarkImmutableAvlTreeWithDB(b, db) } diff --git a/tm2/pkg/sdk/auth/keeper_bench_test.go b/tm2/pkg/sdk/auth/keeper_bench_test.go index 7bd2e9b7f84..305139b1f92 100644 --- a/tm2/pkg/sdk/auth/keeper_bench_test.go +++ b/tm2/pkg/sdk/auth/keeper_bench_test.go @@ -33,12 +33,12 @@ func BenchmarkAccountMapperGetAccountFound(b *testing.B) { func BenchmarkAccountMapperGetAccountFoundWithCoins(b *testing.B) { env := setupTestEnv() coins := std.Coins{ - std.NewCoin("LTC", int64(1000)), - std.NewCoin("BTC", int64(1000)), - std.NewCoin("ETH", int64(1000)), - std.NewCoin("XRP", int64(1000)), - std.NewCoin("BCH", int64(1000)), - std.NewCoin("EOS", int64(1000)), + std.NewCoin("ltc", int64(1000)), + std.NewCoin("btc", int64(1000)), + std.NewCoin("eth", int64(1000)), + std.NewCoin("xrp", int64(1000)), + std.NewCoin("bch", int64(1000)), + std.NewCoin("eos", int64(1000)), } // assumes b.N < 2**24