From 404a984ec00b673314e35230c5822e043215af9d Mon Sep 17 00:00:00 2001 From: jhernandezb Date: Tue, 5 Feb 2019 15:39:55 -0600 Subject: [PATCH 1/5] Upgraded to 0.30 SDK --- .chain/config/config.toml | 2 +- .chain/config/gaiad.toml | 2 +- .gitignore | 2 + Gopkg.lock | 193 +++++++++++++++++--------------- Gopkg.toml | 6 +- app/api.go | 8 +- app/app.go | 53 ++++++--- cmd/truchaind/main.go | 28 ++--- cmd/trucli/main.go | 99 +++++++++++----- types/errors.go | 2 +- x/backing/errors.go | 2 +- x/backing/handler_test.go | 4 +- x/backing/keeper.go | 7 ++ x/backing/test_common.go | 16 ++- x/category/errors.go | 2 +- x/category/handler_test.go | 7 +- x/category/keeper.go | 5 + x/challenge/errors.go | 2 +- x/challenge/keeper.go | 5 + x/challenge/test_common.go | 6 +- x/chttp/api.go | 2 +- x/chttp/presigned.go | 6 +- x/game/errors.go | 2 +- x/game/keeper.go | 9 ++ x/game/test_common.go | 22 ++-- x/story/errors.go | 2 +- x/story/handler_test.go | 10 +- x/story/keeper.go | 5 + x/truapi/handle_registration.go | 4 +- x/users/querier.go | 2 +- x/users/types.go | 4 +- x/vote/errors.go | 2 +- x/vote/keeper.go | 5 + x/vote/test_common.go | 26 +++-- 34 files changed, 336 insertions(+), 216 deletions(-) diff --git a/.chain/config/config.toml b/.chain/config/config.toml index bf463347..0744ce86 100644 --- a/.chain/config/config.toml +++ b/.chain/config/config.toml @@ -8,7 +8,7 @@ proxy_app = "tcp://127.0.0.1:26658" # A custom human readable name for this node -moniker = "" +moniker = "anonymous" # If this node is many blocks behind the tip of the chain, FastSync # allows them to catchup quickly by downloading blocks in parallel diff --git a/.chain/config/gaiad.toml b/.chain/config/gaiad.toml index dd505c25..4c045236 100644 --- a/.chain/config/gaiad.toml +++ b/.chain/config/gaiad.toml @@ -4,4 +4,4 @@ ##### main base config options ##### # Validators reject any tx from the mempool with less than the minimum fee per gas. -minimum_fees = "" +minimum-gas-price = "10trusteak" diff --git a/.gitignore b/.gitignore index 5f10fb1d..3f3a693f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ write-file-atomic-* .chain/data .chain/config/addrbook.json .chain/config/priv_validator.json +.chain/config/priv_validator_key.json +.chain/config/priv_validator.json.bak .chain/config/genesis.json dev/api_spec/.chain diff --git a/Gopkg.lock b/Gopkg.lock index fe865f99..5389bd78 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,12 +2,20 @@ [[projects]] - branch = "master" digest = "1:7736fc6da04620727f8f3aa2ced8d77be8e074a302820937aa5993848c769b27" name = "github.com/ZondaX/hid-go" packages = ["."] pruneopts = "UT" revision = "48b08affede2cea076a3cf13b2e3f72ed262b743" + version = "v0.4.0" + +[[projects]] + digest = "1:1ba351898f7efc68c7c9ff3145b920e478f716b077fdaaf06b967c5d883fa988" + name = "github.com/ZondaX/ledger-go" + packages = ["."] + pruneopts = "UT" + revision = "c3225ab10c2f53397d4aa419a588466493572b22" + version = "v0.4.0" [[projects]] branch = "master" @@ -35,11 +43,11 @@ [[projects]] branch = "master" - digest = "1:c0decf632843204d2b8781de7b26e7038584e2dcccc7e2f401e88ae85b1df2b7" + digest = "1:093bf93a65962e8191e3e8cd8fc6c363f83d43caca9739c906531ba7210a9904" name = "github.com/btcsuite/btcd" packages = ["btcec"] pruneopts = "UT" - revision = "67e573d211ace594f1366b4ce9d39726c4b19bd0" + revision = "ed77733ec07dfc8a513741138419b8d9d3de9d2d" [[projects]] digest = "1:386de157f7d19259a7f9c81f26ce011223ce0f090353c1152ffdf730d7d10ac2" @@ -49,7 +57,7 @@ revision = "d4cc87b860166d00d6b5b9e0d3b3d71d6088d4d4" [[projects]] - digest = "1:7891657129bd1b80ddc0b3934d8607735436c9eda12aafa0e134f2b28619a1e3" + digest = "1:76bdd0a18b13b9f532d5802919d448b77245e4cd5579dce9ab43c493edd65b6f" name = "github.com/cosmos/cosmos-sdk" packages = [ "baseapp", @@ -78,8 +86,10 @@ "x/bank", "x/bank/client", "x/bank/client/cli", + "x/bank/simulation", "x/distribution", "x/distribution/keeper", + "x/distribution/simulation", "x/distribution/tags", "x/distribution/types", "x/gov", @@ -88,19 +98,22 @@ "x/ibc/client/cli", "x/mint", "x/mock", + "x/mock/simulation", "x/params", "x/params/subspace", "x/slashing", - "x/stake", - "x/stake/client/cli", - "x/stake/keeper", - "x/stake/querier", - "x/stake/tags", - "x/stake/types", + "x/slashing/tags", + "x/staking", + "x/staking/client/cli", + "x/staking/keeper", + "x/staking/querier", + "x/staking/simulation", + "x/staking/tags", + "x/staking/types", ] pruneopts = "UT" - revision = "bb54a0de127e45713f272217f578c0abe53a5b21" - version = "v0.26.1-rc1" + revision = "e003c5ebe02bed51056e46d5ff1a232e2bd00dda" + version = "v0.30.0" [[projects]] digest = "1:e8a3550c8786316675ff54ad6f09d265d129c9d986919af7f541afba50d87ce2" @@ -142,12 +155,12 @@ version = "v0.6.0" [[projects]] - digest = "1:31a18dae27a29aa074515e43a443abfd2ba6deb6d69309d8d7ce789c45f34659" + digest = "1:4062bc6de62d73e2be342243cf138cf499b34d558876db8d9430e2149388a4d8" name = "github.com/go-logfmt/logfmt" packages = ["."] pruneopts = "UT" - revision = "390ab7935ee28ec6b286364bba9b4dd6410cb3d5" - version = "v0.3.0" + revision = "07c9b44f60d7ffdfb7d8efe1ad539965737836dc" + version = "v0.4.0" [[projects]] digest = "1:1eb6953835576e98ba19de75b65019d7cf86b2b8d6d458d27bc8d48689d3c5e6" @@ -213,31 +226,23 @@ revision = "2e65f85255dbc3072edf28d6b5b8efc472979f5a" [[projects]] - digest = "1:c79fb010be38a59d657c48c6ba1d003a8aa651fa56b579d959d74573b7dff8e1" - name = "github.com/gorilla/context" - packages = ["."] - pruneopts = "UT" - revision = "08b5f424b9271eedf6f9f0ce86cb9396ed337a42" - version = "v1.1.1" - -[[projects]] - digest = "1:e73f5b0152105f18bc131fba127d9949305c8693f8a762588a82a48f61756f5f" + digest = "1:ca59b1175189b3f0e9f1793d2c350114be36eaabbe5b9f554b35edee1de50aea" name = "github.com/gorilla/mux" packages = ["."] pruneopts = "UT" - revision = "e3702bed27f0d39777b0b37b664b6280e8ef8fbf" - version = "v1.6.2" + revision = "a7962380ca08b5a188038c69871b8d3fbdf31e89" + version = "v1.7.0" [[projects]] - digest = "1:43dd08a10854b2056e615d1b1d22ac94559d822e1f8b6fcc92c1a1057e85188e" + digest = "1:7b5c6e2eeaa9ae5907c391a91c132abfd5c9e8a784a341b5625e750c67e6825d" name = "github.com/gorilla/websocket" packages = ["."] pruneopts = "UT" - revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b" - version = "v1.2.0" + revision = "66b9c49e59c6c48f0ffce28c2d8b8a5678502c6d" + version = "v1.4.0" [[projects]] - digest = "1:3c76995e54de935a870ecfc7147b68ac36a80a7112f9877cd4c46fc88ef42db9" + digest = "1:1782a9b9ef40205e55fc0bb2f467ae1f316c08ff2d9bc4cfc9d1091b71c7327f" name = "github.com/graphql-go/graphql" packages = [ "gqlerrors", @@ -249,16 +254,17 @@ "language/source", ] pruneopts = "UT" - revision = "5c1be0872a56fba73b279434ea95dfda735abedd" - version = "v0.7.6" + revision = "08943645bf265d192b32f2100cdff2428f7ae7c5" + version = "v0.7.7" [[projects]] - digest = "1:ea40c24cdbacd054a6ae9de03e62c5f252479b96c716375aace5c120d68647c8" + digest = "1:c0d19ab64b32ce9fe5cf4ddceba78d5bc9807f0016db6b1183599da3dcc24d10" name = "github.com/hashicorp/hcl" packages = [ ".", "hcl/ast", "hcl/parser", + "hcl/printer", "hcl/scanner", "hcl/strconv", "hcl/token", @@ -334,14 +340,6 @@ revision = "c12348ce28de40eed0136aa2b644d0ee0650e56c" version = "v1.0.1" -[[projects]] - digest = "1:78bbb1ba5b7c3f2ed0ea1eab57bdd3859aec7e177811563edc41198a760b06af" - name = "github.com/mitchellh/go-homedir" - packages = ["."] - pruneopts = "UT" - revision = "ae18d6b8b3205b561c79e8e5f69bff09736185f4" - version = "v1.0.0" - [[projects]] digest = "1:53bc4cd4914cd7cd52139990d5170d6dc99067ae31c56530621b18b35fc30318" name = "github.com/mitchellh/mapstructure" @@ -383,14 +381,16 @@ version = "v1.0.0" [[projects]] - digest = "1:c1a04665f9613e082e1209cf288bf64f4068dcd6c87a64bf1c4ff006ad422ba0" + digest = "1:93a746f1060a8acbcf69344862b2ceced80f854170e1caae089b2834c5fbf7f4" name = "github.com/prometheus/client_golang" packages = [ "prometheus", + "prometheus/internal", "prometheus/promhttp", ] pruneopts = "UT" - revision = "ae27198cdd90bf12cd134ad79d1366a6cf49f632" + revision = "505eaef017263e299324067d40ca2c48f6a2cf50" + version = "v0.9.2" [[projects]] branch = "master" @@ -398,11 +398,10 @@ name = "github.com/prometheus/client_model" packages = ["go"] pruneopts = "UT" - revision = "5c3871d89910bfb32f5fcab2aa4b9ec68e65a99f" + revision = "fd36f4220a901265f90734c3183c5f0c91daa0b8" [[projects]] - branch = "master" - digest = "1:db712fde5d12d6cdbdf14b777f0c230f4ff5ab0be8e35b239fc319953ed577a4" + digest = "1:35cf6bdf68db765988baa9c4f10cc5d7dda1126a54bd62e252dbcd0b1fc8da90" name = "github.com/prometheus/common" packages = [ "expfmt", @@ -410,11 +409,12 @@ "model", ] pruneopts = "UT" - revision = "7e9e6cabbd393fc208072eedef99188d0ce788b6" + revision = "cfeb6f9992ffa54aaa4f2170ade4067ee478b250" + version = "v0.2.0" [[projects]] branch = "master" - digest = "1:ef74914912f99c79434d9c09658274678bc85080ebe3ab32bec3940ebce5e1fc" + digest = "1:5833c61ebbd625a6bad8e5a1ada2b3e13710cf3272046953a2c8915340fe60a3" name = "github.com/prometheus/procfs" packages = [ ".", @@ -423,7 +423,7 @@ "xfs", ] pruneopts = "UT" - revision = "185b4288413d2a0dd0806f78c90dde719829e5ae" + revision = "488faf799f863e27e50c516468f76ae8f1da20a5" [[projects]] digest = "1:ea0700160aca4ef099f4e06686a665a87691f4248dddd40796925eda2e46bd64" @@ -440,6 +440,14 @@ pruneopts = "UT" revision = "e2704e165165ec55d062f5919b4b29494e9fa790" +[[projects]] + digest = "1:b0c25f00bad20d783d259af2af8666969e2fc343fa0dc9efe52936bbd67fb758" + name = "github.com/rs/cors" + packages = ["."] + pruneopts = "UT" + revision = "9a47f48565a795472d43519dd49aac781f3034fb" + version = "v1.6.0" + [[projects]] digest = "1:b579c92271e8cbaf43662ea9b19b036e283565b345d94f10a9f683b8b31abc0f" name = "github.com/samsarahq/thunder" @@ -460,31 +468,31 @@ version = "v0.4.0" [[projects]] - digest = "1:6a4a11ba764a56d2758899ec6f3848d24698d48442ebce85ee7a3f63284526cd" + digest = "1:3e39bafd6c2f4bf3c76c3bfd16a2e09e016510ad5db90dc02b88e2f565d6d595" name = "github.com/spf13/afero" packages = [ ".", "mem", ] pruneopts = "UT" - revision = "d40851caa0d747393da1ffb28f7f9d8b4eeffebd" - version = "v1.1.2" + revision = "f4711e4db9e9a1d3887343acb72b2bbfc2f686f5" + version = "v1.2.1" [[projects]] - digest = "1:516e71bed754268937f57d4ecb190e01958452336fa73dbac880894164e91c1f" + digest = "1:08d65904057412fc0270fc4812a1c90c594186819243160dc779a402d4b6d0bc" name = "github.com/spf13/cast" packages = ["."] pruneopts = "UT" - revision = "8965335b8c7107321228e3e3702cab9832751bac" - version = "v1.2.0" + revision = "8c9545af88b134710ab1cd196795e7f2388358d7" + version = "v1.3.0" [[projects]] - digest = "1:7ffc0983035bc7e297da3688d9fe19d60a420e9c38bef23f845c53788ed6a05e" + digest = "1:645cabccbb4fa8aab25a956cbcbdf6a6845ca736b2c64e197ca7cbb9d210b939" name = "github.com/spf13/cobra" packages = ["."] pruneopts = "UT" - revision = "7b2c5ac9fc04fc5efafb60700713d4fa609b777b" - version = "v0.0.1" + revision = "ef82de70bb3f60c65fb8eebacbb2d122ef517385" + version = "v0.0.3" [[projects]] digest = "1:68ea4e23713989dc20b1bded5d9da2c5f9be14ff9885beef481848edd18c26cb" @@ -503,12 +511,12 @@ version = "v1.0.3" [[projects]] - digest = "1:f8e1a678a2571e265f4bf91a3e5e32aa6b1474a55cb0ea849750cc177b664d96" + digest = "1:ba07ec7953d565ac57a11b123a3bf0c8e848f2c7f637fccb0f9ce4f9e489d69a" name = "github.com/spf13/viper" packages = ["."] pruneopts = "UT" - revision = "25b30aa063fc18e48662b86996252eabdcf2f0c7" - version = "v1.0.0" + revision = "a1b837276271029e31f796ae5d03ba9ffb017244" + version = "v1.0.3" [[projects]] digest = "1:7e8d267900c7fa7f35129a2a37596e38ed0f11ca746d6d9ba727980ee138f9f6" @@ -523,7 +531,7 @@ [[projects]] branch = "master" - digest = "1:59483b8e8183f10ab21a85ba1f4cbb4a2335d48891801f79ed7b9499f44d383c" + digest = "1:685fdfea42d825ebd39ee0994354b46c374cf2c2b2d97a41a8dee1807c6a9b62" name = "github.com/syndtr/goleveldb" packages = [ "leveldb", @@ -540,22 +548,23 @@ "leveldb/util", ] pruneopts = "UT" - revision = "6b91fda63f2e36186f1c9d0e48578defb69c5d43" + revision = "2f17a3356c6616cbfc4ae4c38147dc062a68fb0e" [[projects]] - digest = "1:605b6546f3f43745695298ec2d342d3e952b6d91cdf9f349bea9315f677d759f" + digest = "1:83f5e189eea2baad419a6a410984514266ff690075759c87e9ede596809bd0b8" name = "github.com/tendermint/btcd" packages = ["btcec"] pruneopts = "UT" - revision = "e5840949ff4fff0c56f9b6a541e22b63581ea9df" + revision = "80daadac05d1cd29571fccf27002d79667a88b58" + version = "v0.1.1" [[projects]] - digest = "1:10b3a599325740c84a7c81f3f3cb2e1fdb70b3ea01b7fa28495567a2519df431" + digest = "1:ad9c4c1a4e7875330b1f62906f2830f043a23edb5db997e3a5ac5d3e6eadf80a" name = "github.com/tendermint/go-amino" packages = ["."] pruneopts = "UT" - revision = "6dcc6ddc143e116455c94b25c1004c99e0d0ca12" - version = "v0.14.0" + revision = "dc14acf9ef15f85828bfbc561ed9dd9d2a284885" + version = "v0.14.1" [[projects]] digest = "1:9f8c4c93658315a795ffd3e0c943d39f78067dd8382b8d7bcfaf6686b92f3978" @@ -566,11 +575,12 @@ version = "v0.11.1" [[projects]] - digest = "1:5b1373b03f39e6f6061cd91f3829100527ebb5f94240c092bf9e5d314b153501" + digest = "1:22a0fe58c626dd09549eb9451688fab5a2c8bef04d478c907f747d6151d431fd" name = "github.com/tendermint/tendermint" packages = [ "abci/client", "abci/example/code", + "abci/example/counter", "abci/example/kvstore", "abci/server", "abci/types", @@ -597,7 +607,6 @@ "libs/clist", "libs/common", "libs/db", - "libs/errors", "libs/events", "libs/fail", "libs/flowrate", @@ -632,8 +641,8 @@ "version", ] pruneopts = "UT" - revision = "48ab899923c564bbf2fa2f1244c11cb930e28132" - version = "v0.26.1-rc3" + revision = "4514842a631059a4148026ebce0e46fdf628f875" + version = "v0.29.0" [[projects]] digest = "1:bf6d9a827ea3cad964c2f863302e4f6823170d0b5ed16f72cf1184a7c615067e" @@ -644,12 +653,12 @@ version = "v0.9.0" [[projects]] - digest = "1:7886f86064faff6f8d08a3eb0e8c773648ff5a2e27730831e2bfbf07467f6666" - name = "github.com/zondax/ledger-goclient" + digest = "1:99e67ddd04c24df5df5bcbaacbd7592137ff348b3aac5de4dfc161aba053df62" + name = "github.com/zondax/ledger-cosmos-go" packages = ["."] pruneopts = "UT" - revision = "58598458c11bc0ad1c1b8dac3dc3e11eaf270b79" - version = "v0.1.0" + revision = "394d5af1e2a5c564aca3541a3348fa4152976a80" + version = "v0.9.2" [[projects]] digest = "1:6f6dc6060c4e9ba73cf28aa88f12a69a030d3d19d518ef8e931879eaa099628d" @@ -695,14 +704,14 @@ [[projects]] branch = "master" - digest = "1:d1da39c9bac61327dbef1d8ef9f210425e99fd2924b6fb5f0bc587a193353637" + digest = "1:f7cca3d5557222642e9e15537a1f03b1b9dbdbaf26f5ae177c7db4d2d5408c85" name = "golang.org/x/sys" packages = [ "cpu", "unix", ] pruneopts = "UT" - revision = "8a28ead16f52c8aaeffbf79239b251dfdf6c4f96" + revision = "7ae0202eb74c2b534255c71b5a15fa4115aabbcc" [[projects]] digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" @@ -729,30 +738,37 @@ [[projects]] branch = "master" - digest = "1:56b0bca90b7e5d1facf5fbdacba23e4e0ce069d25381b8e2f70ef1e7ebfb9c1a" + digest = "1:077c1c599507b3b3e9156d17d36e1e61928ee9b53a5b420f10f28ebd4a0b275c" name = "google.golang.org/genproto" packages = ["googleapis/rpc/status"] pruneopts = "UT" - revision = "94acd270e44e65579b9ee3cdab25034d33fed608" + revision = "4b09977fb92221987e99d190c8f88f2c92727a29" [[projects]] - digest = "1:2dab32a43451e320e49608ff4542fdfc653c95dcc35d0065ec9c6c3dd540ed74" + digest = "1:9ab5a33d8cb5c120602a34d2e985ce17956a4e8c2edce7e6961568f95e40c09a" name = "google.golang.org/grpc" packages = [ ".", "balancer", "balancer/base", "balancer/roundrobin", + "binarylog/grpc_binarylog_v1", "codes", "connectivity", "credentials", + "credentials/internal", "encoding", "encoding/proto", "grpclog", "internal", "internal/backoff", + "internal/binarylog", "internal/channelz", + "internal/envconfig", "internal/grpcrand", + "internal/grpcsync", + "internal/syscall", + "internal/transport", "keepalive", "metadata", "naming", @@ -763,19 +779,18 @@ "stats", "status", "tap", - "transport", ] pruneopts = "UT" - revision = "168a6198bcb0ef175f7dacec0b8691fc141dc9b8" - version = "v1.13.0" + revision = "a02b0774206b209466313a0b525d2c738fe407eb" + version = "v1.18.0" [[projects]] - digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202" + digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96" name = "gopkg.in/yaml.v2" packages = ["."] pruneopts = "UT" - revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" - version = "v2.2.1" + revision = "51d6538a90f86fe93ac480b35f37b2be17fef232" + version = "v2.2.2" [[projects]] digest = "1:999d566ad1ae4303c456af5a155f7b42401cca4fd33552567ed9dd997b107a08" @@ -806,7 +821,9 @@ "github.com/cosmos/cosmos-sdk/x/bank/client/cli", "github.com/cosmos/cosmos-sdk/x/ibc", "github.com/cosmos/cosmos-sdk/x/ibc/client/cli", - "github.com/cosmos/cosmos-sdk/x/stake/client/cli", + "github.com/cosmos/cosmos-sdk/x/params", + "github.com/cosmos/cosmos-sdk/x/staking", + "github.com/cosmos/cosmos-sdk/x/staking/client/cli", "github.com/go-pg/pg", "github.com/go-pg/pg/orm", "github.com/gorilla/mux", diff --git a/Gopkg.toml b/Gopkg.toml index 2914e98c..874e32d5 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -21,7 +21,7 @@ [[constraint]] name = "github.com/cosmos/cosmos-sdk" - version = "=v0.26.1-rc1" + version = "=v0.30.0" [[constraint]] name = "github.com/go-pg/pg" @@ -37,11 +37,11 @@ [[override]] name = "github.com/tendermint/tendermint" - version = "=0.26.1-rc3" + version = "=v0.29.0" [[override]] name = "github.com/tendermint/go-amino" - version = "=v0.14.0" + version = "=v0.14.1" [[constraint]] name = "github.com/samsarahq/thunder" diff --git a/app/api.go b/app/api.go index 698aff60..1320aac9 100644 --- a/app/api.go +++ b/app/api.go @@ -56,7 +56,7 @@ func (app *TruChain) startAPI() { // RegisterKey generates a new address/account for a public key // Implements chttp.App -func (app *TruChain) RegisterKey(k tcmn.HexBytes, algo string) (sdk.AccAddress, int64, sdk.Coins, error) { +func (app *TruChain) RegisterKey(k tcmn.HexBytes, algo string) (sdk.AccAddress, uint64, sdk.Coins, error) { var addr []byte if string(algo[0]) == "*" { @@ -147,10 +147,8 @@ func (app *TruChain) signedRegistrationTx(addr []byte, k tcmn.HexBytes, algo str Msgs: []sdk.Msg{msg}, Fee: params.RegistrationFee, Signatures: []auth.StdSignature{auth.StdSignature{ - PubKey: app.registrarKey.PubKey(), - Signature: sigBytes, - AccountNumber: 1, - Sequence: registrarSequence, + PubKey: app.registrarKey.PubKey(), + Signature: sigBytes, }}, Memo: registrationMemo, } diff --git a/app/app.go b/app/app.go index 2c34c32b..4f63749a 100644 --- a/app/app.go +++ b/app/app.go @@ -24,6 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/ibc" + sdkparams "github.com/cosmos/cosmos-sdk/x/params" "github.com/joho/godotenv" "github.com/spf13/viper" abci "github.com/tendermint/tendermint/abci/types" @@ -63,12 +64,15 @@ type TruChain struct { keyMain *sdk.KVStoreKey keyStory *sdk.KVStoreKey keyVote *sdk.KVStoreKey + keyParams *sdk.KVStoreKey + tkeyParams *sdk.TransientStoreKey // manage getting and setting accounts accountKeeper auth.AccountKeeper feeCollectionKeeper auth.FeeCollectionKeeper coinKeeper bank.Keeper ibcMapper ibc.Mapper + paramsKeeper sdkparams.Keeper // access truchain database storyKeeper story.WriteKeeper @@ -124,19 +128,21 @@ func NewTruChain(logger log.Logger, db dbm.DB, options ...func(*bam.BaseApp)) *T categories: categories, codec: codec, BaseApp: bam.NewBaseApp(params.AppName, logger, db, auth.DefaultTxDecoder(codec), options...), - keyMain: sdk.NewKVStoreKey("main"), - keyAccount: sdk.NewKVStoreKey("acc"), + keyMain: sdk.NewKVStoreKey(bam.MainStoreKey), + keyAccount: sdk.NewKVStoreKey(auth.StoreKey), keyIBC: sdk.NewKVStoreKey("ibc"), - keyStory: sdk.NewKVStoreKey("stories"), - keyCategory: sdk.NewKVStoreKey("categories"), - keyBacking: sdk.NewKVStoreKey("backings"), - keyBackingList: sdk.NewKVStoreKey("backingList"), - keyChallenge: sdk.NewKVStoreKey("challenges"), + keyStory: sdk.NewKVStoreKey(story.StoreKey), + keyCategory: sdk.NewKVStoreKey(category.StoreKey), + keyBacking: sdk.NewKVStoreKey(backing.StoreKey), + keyBackingList: sdk.NewKVStoreKey(backing.ListStoreKey), + keyChallenge: sdk.NewKVStoreKey(challenge.StoreKey), keyFee: sdk.NewKVStoreKey("collectedFees"), - keyGame: sdk.NewKVStoreKey("game"), - keyPendingGameList: sdk.NewKVStoreKey("pendingGameList"), - keyGameQueue: sdk.NewKVStoreKey("gameQueue"), - keyVote: sdk.NewKVStoreKey("vote"), + keyGame: sdk.NewKVStoreKey(game.StoreKey), + keyPendingGameList: sdk.NewKVStoreKey(game.PendingListStoreKey), + keyGameQueue: sdk.NewKVStoreKey(game.QueueStoreKey), + keyVote: sdk.NewKVStoreKey(vote.StoreKey), + keyParams: sdk.NewKVStoreKey(sdkparams.StoreKey), + tkeyParams: sdk.NewTransientStoreKey(sdkparams.TStoreKey), api: nil, apiStarted: false, blockCtx: nil, @@ -144,14 +150,18 @@ func NewTruChain(logger log.Logger, db dbm.DB, options ...func(*bam.BaseApp)) *T registrarKey: loadRegistrarKey(), } + app.paramsKeeper = sdkparams.NewKeeper(codec, app.keyParams, app.tkeyParams) + // define and attach the mappers and keepers app.accountKeeper = auth.NewAccountKeeper( codec, - app.keyAccount, // target store + app.keyAccount, // target store, + app.paramsKeeper.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount, // prototype ) + app.coinKeeper = bank.NewBaseKeeper(app.accountKeeper) - app.ibcMapper = ibc.NewMapper(app.codec, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace)) + app.ibcMapper = ibc.NewMapper(app.codec, app.keyIBC, ibc.DefaultCodespace) app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.codec, app.keyFee) // wire up keepers @@ -232,13 +242,20 @@ func NewTruChain(logger log.Logger, db dbm.DB, options ...func(*bam.BaseApp)) *T app.SetEndBlocker(app.EndBlocker) app.SetAnteHandler(auth.NewAnteHandler(app.accountKeeper, app.feeCollectionKeeper)) - // set fee for spam prevention and validator rewards - if params.Features[params.FeeFlag] { - app.SetMinimumFees(params.Fee) - } + // + // TODO: + // SetMininumFees is now unpexpored + // instead minimum gas price is loaded from config/gaid.tom + // also there is a refactor in place where + // SetMinGasPrices is a new exported function for this purpose (not yet released) + // See https://github.com/cosmos/cosmos-sdk/pull/3258 + // + // if params.Features[params.FeeFlag] { + // app.SetMinGasPrices(params.Fee) + // } // mount the multistore and load the latest state - app.MountStoresIAVL( + app.MountStores( app.keyAccount, app.keyBacking, app.keyBackingList, diff --git a/cmd/truchaind/main.go b/cmd/truchaind/main.go index 8366c222..3f30f5d0 100644 --- a/cmd/truchaind/main.go +++ b/cmd/truchaind/main.go @@ -38,17 +38,9 @@ func main() { PersistentPreRunE: server.PersistentPreRunEFn(ctx), } - appInit := server.DefaultAppInit - rootCmd.AddCommand(InitCmd(ctx, cdc, appInit)) - rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc, appInit)) - - server.AddCommands( - ctx, - cdc, - rootCmd, - appInit, - newApp, - exportAppStateAndTMValidators) + rootCmd.AddCommand(InitCmd(ctx, cdc)) + rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc)) + server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators) // prepare and add flags rootDir := os.ExpandEnv("$HOME/.truchaind") @@ -63,13 +55,12 @@ func main() { // InitCmd get cmd to initialize all files for tendermint and application // nolint: errcheck -func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cobra.Command { +func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "init", Short: "Initialize genesis config, priv-validator file, and p2p-node file", Args: cobra.NoArgs, RunE: func(_ *cobra.Command, _ []string) error { - config := ctx.Config config.SetRoot(viper.GetString(cli.HomeFlag)) chainID := viper.GetString(client.FlagChainID) @@ -83,13 +74,18 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob } nodeID := string(nodeKey.ID()) - pk := gaiaInit.ReadOrCreatePrivValidator(config.PrivValidatorFile()) + // initalize files and upgrades priv_validator file format (< v0.28) + _, pk, err := gaiaInit.InitializeNodeValidatorFiles(config) + if err != nil { + return err + } + genTx, appMessage, validator, err := server.SimpleAppGenTx(cdc, pk) if err != nil { return err } - appState, err := appInit.AppGenState( + appState, err := server.SimpleAppGenState( cdc, tmtypes.GenesisDoc{}, []json.RawMessage{genTx}) if err != nil { return err @@ -130,7 +126,7 @@ func newApp(logger log.Logger, db dbm.DB, _ io.Writer) abci.Application { return app.NewTruChain(logger, db) } -func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, _ io.Writer) (json.RawMessage, []tmtypes.GenesisValidator, error) { +func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, _ io.Writer, _ int64, _ bool) (json.RawMessage, []tmtypes.GenesisValidator, error) { bapp := app.NewTruChain(logger, db) return bapp.ExportAppStateAndValidators() } diff --git a/cmd/trucli/main.go b/cmd/trucli/main.go index ab1a5d78..d77a2e74 100644 --- a/cmd/trucli/main.go +++ b/cmd/trucli/main.go @@ -4,16 +4,19 @@ import ( "os" "github.com/TruStory/truchain/app" - "github.com/TruStory/truchain/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" ibccmd "github.com/cosmos/cosmos-sdk/x/ibc/client/cli" - stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingcmd "github.com/cosmos/cosmos-sdk/x/staking/client/cli" "github.com/spf13/cobra" "github.com/tendermint/tmlibs/cli" ) @@ -37,40 +40,25 @@ func main() { // the below functions and eliminate global vars, like we do // with the cdc. - // add standard rpc, and tx commands - rpc.AddCommands(rootCmd) - rootCmd.AddCommand(client.LineBreak) - tx.AddCommands(rootCmd, cdc) - rootCmd.AddCommand(client.LineBreak) + mc := []sdk.ModuleClients{} - // add query/post commands (custom to binary) - rootCmd.AddCommand( - client.GetCommands( - stakecmd.GetCmdQueryValidator("stake", cdc), - stakecmd.GetCmdQueryValidators("stake", cdc), - stakecmd.GetCmdQueryDelegation("stake", cdc), - stakecmd.GetCmdQueryDelegations("stake", cdc), - authcmd.GetAccountCmd("acc", cdc, types.GetAccountDecoder(cdc)), - )...) + // Read in the configuration file for the sdk + config := sdk.GetConfig() + config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub) + config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub) + config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub) + config.Seal() + // Construct Root Command rootCmd.AddCommand( - client.PostCommands( - bankcmd.SendTxCmd(cdc), - ibccmd.IBCTransferCmd(cdc), - ibccmd.IBCRelayCmd(cdc), - stakecmd.GetCmdCreateValidator(cdc), - stakecmd.GetCmdEditValidator(cdc), - stakecmd.GetCmdDelegate(cdc), - stakecmd.GetCmdUnbond("stake", cdc), - )...) - - // add proxy, version and key info - rootCmd.AddCommand( + rpc.StatusCommand(), + client.ConfigCmd(), + queryCmd(cdc, mc), + txCmd(cdc, mc), client.LineBreak, keys.Commands(), client.LineBreak, - version.VersionCmd, - ) + version.VersionCmd) // prepare and add flags executor := cli.PrepareMainCmd(rootCmd, "BC", os.ExpandEnv("$HOME/.trucli")) @@ -80,3 +68,54 @@ func main() { panic(err) } } + +func queryCmd(cdc *codec.Codec, mc []sdk.ModuleClients) *cobra.Command { + queryCmd := &cobra.Command{ + Use: "query", + Aliases: []string{"q"}, + Short: "Querying subcommands", + } + + queryCmd.AddCommand( + rpc.ValidatorCommand(), + rpc.BlockCommand(), + tx.SearchTxCmd(cdc), + tx.QueryTxCmd(cdc), + client.LineBreak, + authcmd.GetAccountCmd("acc", cdc), + ) + + for _, m := range mc { + queryCmd.AddCommand(m.GetQueryCmd()) + } + + return queryCmd +} + +func txCmd(cdc *codec.Codec, mc []sdk.ModuleClients) *cobra.Command { + txCmd := &cobra.Command{ + Use: "tx", + Short: "Transactions subcommands", + } + + txCmd.AddCommand( + bankcmd.SendTxCmd(cdc), + ibccmd.IBCTransferCmd(cdc), + ibccmd.IBCRelayCmd(cdc), + stakingcmd.GetCmdCreateValidator(cdc), + stakingcmd.GetCmdEditValidator(cdc), + stakingcmd.GetCmdDelegate(cdc), + stakingcmd.GetCmdUnbond(staking.StoreKey, cdc), + client.LineBreak, + authcmd.GetSignCommand(cdc), + authcmd.GetMultiSignCommand(cdc), + bankcmd.GetBroadcastCommand(cdc), + client.LineBreak, + ) + + for _, m := range mc { + txCmd.AddCommand(m.GetTxCmd()) + } + + return txCmd +} diff --git a/types/errors.go b/types/errors.go index a2dc8e65..ee4b8a81 100644 --- a/types/errors.go +++ b/types/errors.go @@ -6,7 +6,7 @@ import ( // App errors reserve 100 ~ 199. const ( - DefaultCodespace sdk.CodespaceType = 1 + DefaultCodespace sdk.CodespaceType = "types" CodeInvalidArgumentMsg sdk.CodeType = 101 ) diff --git a/x/backing/errors.go b/x/backing/errors.go index c40fbf8a..e7cc4da6 100644 --- a/x/backing/errors.go +++ b/x/backing/errors.go @@ -9,7 +9,7 @@ import ( // Story errors reserve 700 ~ 799. const ( - DefaultCodespace sdk.CodespaceType = 9 + DefaultCodespace sdk.CodespaceType = "backing" CodeInvalidPeriod sdk.CodeType = 901 CodeQueueEmpty sdk.CodeType = 902 diff --git a/x/backing/handler_test.go b/x/backing/handler_test.go index 2f689d7b..decc22c3 100644 --- a/x/backing/handler_test.go +++ b/x/backing/handler_test.go @@ -47,8 +47,8 @@ func TestBackStoryMsg_FailInsufficientFunds(t *testing.T) { assert.NotNil(t, msg) res := h(ctx, msg) - hasInsufficientFunds := strings.Contains(res.Log, "65541") - assert.True(t, hasInsufficientFunds, "should return err code") + assert.Equal(t, sdk.CodeInsufficientFunds, res.Code) + assert.Equal(t, sdk.CodespaceRoot, res.Codespace) } func TestBackStoryMsg(t *testing.T) { diff --git a/x/backing/keeper.go b/x/backing/keeper.go index 758beaeb..ff759baa 100644 --- a/x/backing/keeper.go +++ b/x/backing/keeper.go @@ -14,6 +14,13 @@ import ( amino "github.com/tendermint/go-amino" ) +const ( + // StoreKey is string representation of the store key for backings + StoreKey = "backings" + // ListStoreKey is string representation of the store key for backing list + ListStoreKey = "backingList" +) + // ReadKeeper defines a module interface that facilitates read only access type ReadKeeper interface { app.ReadKeeper diff --git a/x/backing/test_common.go b/x/backing/test_common.go index dc1783c2..26c7587c 100644 --- a/x/backing/test_common.go +++ b/x/backing/test_common.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/params" amino "github.com/tendermint/go-amino" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" @@ -28,14 +29,16 @@ func mockDB() ( db := dbm.NewMemDB() - accKey := sdk.NewKVStoreKey("acc") - storyKey := sdk.NewKVStoreKey("stories") - catKey := sdk.NewKVStoreKey("categories") - backingKey := sdk.NewKVStoreKey("backings") - backingListKey := sdk.NewKVStoreKey("backingList") + accKey := sdk.NewKVStoreKey(auth.StoreKey) + storyKey := sdk.NewKVStoreKey(story.StoreKey) + catKey := sdk.NewKVStoreKey(category.StoreKey) + backingKey := sdk.NewKVStoreKey(StoreKey) + backingListKey := sdk.NewKVStoreKey(ListStoreKey) pendingGameListKey := sdk.NewKVStoreKey("pendingGameList") gameQueueKey := sdk.NewKVStoreKey("gameQueue") challengeKey := sdk.NewKVStoreKey("challenges") + paramsKey := sdk.NewKVStoreKey(params.StoreKey) + transientParamsKey := sdk.NewTransientStoreKey(params.TStoreKey) ms := store.NewCommitMultiStore(db) ms.MountStoreWithDB(accKey, sdk.StoreTypeIAVL, db) @@ -57,7 +60,8 @@ func mockDB() ( codec.RegisterConcrete(&auth.BaseAccount{}, "auth/Account", nil) ck := category.NewKeeper(catKey, codec) - am := auth.NewAccountKeeper(codec, accKey, auth.ProtoBaseAccount) + pk := params.NewKeeper(codec, paramsKey, transientParamsKey) + am := auth.NewAccountKeeper(codec, accKey, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) bankKeeper := bank.NewBaseKeeper(am) sk := story.NewKeeper(storyKey, ck, codec) bk := NewKeeper( diff --git a/x/category/errors.go b/x/category/errors.go index 646ce52b..f5ead281 100644 --- a/x/category/errors.go +++ b/x/category/errors.go @@ -8,7 +8,7 @@ import ( // Category errors reserve 800 ~ 899. const ( - DefaultCodespace sdk.CodespaceType = 8 + DefaultCodespace sdk.CodespaceType = "category" CodeInvalidCategory sdk.CodeType = 801 CodeCategoryNotFound sdk.CodeType = 802 diff --git a/x/category/handler_test.go b/x/category/handler_test.go index 8450235f..f5df9d47 100644 --- a/x/category/handler_test.go +++ b/x/category/handler_test.go @@ -2,7 +2,6 @@ package category import ( "encoding/json" - "strings" "testing" "github.com/TruStory/truchain/types" @@ -41,6 +40,8 @@ func TestByzantineMsg(t *testing.T) { assert.NotNil(t, h) res := h(ctx, nil) - hasUnrecognizedMessage := strings.Contains(res.Log, "65542") - assert.True(t, hasUnrecognizedMessage, "should return err code") + + assert.Equal(t, sdk.CodeUnknownRequest, res.Code) + assert.Equal(t, sdk.CodespaceRoot, res.Codespace) + } diff --git a/x/category/keeper.go b/x/category/keeper.go index c054c138..d1f99716 100644 --- a/x/category/keeper.go +++ b/x/category/keeper.go @@ -8,6 +8,11 @@ import ( amino "github.com/tendermint/go-amino" ) +const ( + // StoreKey is string representation of the store key for categories + StoreKey = "categories" +) + // ReadKeeper defines a module interface that facilitates read only access type ReadKeeper interface { app.ReadKeeper diff --git a/x/challenge/errors.go b/x/challenge/errors.go index feda8400..20d49573 100644 --- a/x/challenge/errors.go +++ b/x/challenge/errors.go @@ -9,7 +9,7 @@ import ( // Challenge errors reserve 1000 ~ 1099. const ( - DefaultCodespace sdk.CodespaceType = 10 + DefaultCodespace sdk.CodespaceType = "challenge" CodeNotFound sdk.CodeType = 1001 CodeInvalidMsg sdk.CodeType = 1002 diff --git a/x/challenge/keeper.go b/x/challenge/keeper.go index 65f768da..c972c3c8 100644 --- a/x/challenge/keeper.go +++ b/x/challenge/keeper.go @@ -16,6 +16,11 @@ import ( amino "github.com/tendermint/go-amino" ) +const ( + // StoreKey is string representation of the store key for challenges + StoreKey = "challenges" +) + // ReadKeeper defines a module interface that facilitates read only access to truchain data type ReadKeeper interface { app.ReadKeeper diff --git a/x/challenge/test_common.go b/x/challenge/test_common.go index 3b39b5b9..76d514d3 100644 --- a/x/challenge/test_common.go +++ b/x/challenge/test_common.go @@ -14,6 +14,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/params" amino "github.com/tendermint/go-amino" abci "github.com/tendermint/tendermint/abci/types" cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" @@ -33,6 +34,8 @@ func mockDB() (sdk.Context, Keeper, story.Keeper, c.Keeper, bank.Keeper) { gameQueueKey := sdk.NewKVStoreKey("gameQueue") backingKey := sdk.NewKVStoreKey("backings") backingListKey := sdk.NewKVStoreKey("backingList") + paramsKey := sdk.NewKVStoreKey(params.StoreKey) + transientParamsKey := sdk.NewTransientStoreKey(params.TStoreKey) ms := store.NewCommitMultiStore(db) ms.MountStoreWithDB(accKey, sdk.StoreTypeIAVL, db) @@ -56,7 +59,8 @@ func mockDB() (sdk.Context, Keeper, story.Keeper, c.Keeper, bank.Keeper) { codec.RegisterInterface((*auth.Account)(nil), nil) codec.RegisterConcrete(&auth.BaseAccount{}, "auth/Account", nil) - am := auth.NewAccountKeeper(codec, accKey, auth.ProtoBaseAccount) + pk := params.NewKeeper(codec, paramsKey, transientParamsKey) + am := auth.NewAccountKeeper(codec, accKey, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) bankKeeper := bank.NewBaseKeeper(am) ck := c.NewKeeper(catKey, codec) sk := story.NewKeeper(storyKey, ck, codec) diff --git a/x/chttp/api.go b/x/chttp/api.go index a7d5e7a9..1759f280 100644 --- a/x/chttp/api.go +++ b/x/chttp/api.go @@ -16,7 +16,7 @@ type MsgTypes map[string]interface{} // App is implemented by a Cosmos app to provide chain functionality to the API type App interface { - RegisterKey(tcmn.HexBytes, string) (sdk.AccAddress, int64, sdk.Coins, error) + RegisterKey(tcmn.HexBytes, string) (sdk.AccAddress, uint64, sdk.Coins, error) RunQuery(string, interface{}) abci.ResponseQuery DeliverPresigned(auth.StdTx) (*trpctypes.ResultBroadcastTxCommit, error) } diff --git a/x/chttp/presigned.go b/x/chttp/presigned.go index a7b6d533..2df59fa3 100644 --- a/x/chttp/presigned.go +++ b/x/chttp/presigned.go @@ -145,10 +145,8 @@ func (a *API) stdSignatures(r PresignedRequest, d auth.StdSignDoc) ([]auth.StdSi } stdSig := auth.StdSignature{ - PubKey: key, - Signature: r.Signature.Bytes(), - AccountNumber: d.AccountNumber, - Sequence: d.Sequence, + PubKey: key, + Signature: r.Signature.Bytes(), } sigs := []auth.StdSignature{stdSig} diff --git a/x/game/errors.go b/x/game/errors.go index 2735baa0..0715e202 100644 --- a/x/game/errors.go +++ b/x/game/errors.go @@ -8,7 +8,7 @@ import ( // Game errors reserve 1100 ~ 1199. const ( - DefaultCodespace sdk.CodespaceType = 11 + DefaultCodespace sdk.CodespaceType = "game" CodeNotFound sdk.CodeType = 1101 CodeDuplicate sdk.CodeType = 1102 diff --git a/x/game/keeper.go b/x/game/keeper.go index 90f40ace..ef9ad720 100644 --- a/x/game/keeper.go +++ b/x/game/keeper.go @@ -15,6 +15,15 @@ import ( amino "github.com/tendermint/go-amino" ) +const ( + // StoreKey is string representation of the store key for games + StoreKey = "games" + // QueueStoreKey is string representation of the store key for game queue. + QueueStoreKey = "gameQueue" + // PendingListStoreKey is string representation of the store key for the list of pending games. + PendingListStoreKey = "pendingGameList" +) + // ReadKeeper defines a module interface that facilitates read only access to truchain data type ReadKeeper interface { app.ReadKeeper diff --git a/x/game/test_common.go b/x/game/test_common.go index 6e932ba7..9ccdb0e1 100644 --- a/x/game/test_common.go +++ b/x/game/test_common.go @@ -11,6 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/params" amino "github.com/tendermint/go-amino" abci "github.com/tendermint/tendermint/abci/types" cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" @@ -21,15 +22,17 @@ import ( func mockDB() (sdk.Context, Keeper, c.Keeper) { db := dbm.NewMemDB() - accKey := sdk.NewKVStoreKey("acc") - storyKey := sdk.NewKVStoreKey("stories") - catKey := sdk.NewKVStoreKey("categories") + accKey := sdk.NewKVStoreKey(auth.StoreKey) + storyKey := sdk.NewKVStoreKey(story.StoreKey) + catKey := sdk.NewKVStoreKey(c.StoreKey) challengeKey := sdk.NewKVStoreKey("challenges") - gameKey := sdk.NewKVStoreKey("games") - pendingGameListKey := sdk.NewKVStoreKey("pendingGameList") - gameQueueKey := sdk.NewKVStoreKey("gameQueue") - backingKey := sdk.NewKVStoreKey("backings") - backingListKey := sdk.NewKVStoreKey("backingList") + gameKey := sdk.NewKVStoreKey(StoreKey) + pendingGameListKey := sdk.NewKVStoreKey(PendingListStoreKey) + gameQueueKey := sdk.NewKVStoreKey(QueueStoreKey) + backingKey := sdk.NewKVStoreKey(backing.StoreKey) + backingListKey := sdk.NewKVStoreKey(backing.ListStoreKey) + paramsKey := sdk.NewKVStoreKey(params.StoreKey) + transientParamsKey := sdk.NewTransientStoreKey(params.TStoreKey) ms := store.NewCommitMultiStore(db) ms.MountStoreWithDB(accKey, sdk.StoreTypeIAVL, db) @@ -51,7 +54,8 @@ func mockDB() (sdk.Context, Keeper, c.Keeper) { codec.RegisterInterface((*auth.Account)(nil), nil) codec.RegisterConcrete(&auth.BaseAccount{}, "auth/Account", nil) - am := auth.NewAccountKeeper(codec, accKey, auth.ProtoBaseAccount) + pk := params.NewKeeper(codec, paramsKey, transientParamsKey) + am := auth.NewAccountKeeper(codec, accKey, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) bankKeeper := bank.NewBaseKeeper(am) ck := c.NewKeeper(catKey, codec) sk := story.NewKeeper(storyKey, ck, codec) diff --git a/x/story/errors.go b/x/story/errors.go index 407aaf4c..d89f8bc9 100644 --- a/x/story/errors.go +++ b/x/story/errors.go @@ -8,7 +8,7 @@ import ( // Story errors reserve 700 ~ 799. const ( - DefaultCodespace sdk.CodespaceType = 7 + DefaultCodespace sdk.CodespaceType = "story" CodeInvalidStoryBody sdk.CodeType = 701 CodeInvalidStoryID sdk.CodeType = 702 diff --git a/x/story/handler_test.go b/x/story/handler_test.go index 26eac778..b1337e4b 100644 --- a/x/story/handler_test.go +++ b/x/story/handler_test.go @@ -2,7 +2,6 @@ package story import ( "encoding/json" - "strings" "testing" "github.com/TruStory/truchain/types" @@ -112,8 +111,9 @@ func TestSubmitStoryMsg_ErrInvalidCategory(t *testing.T) { assert.NotNil(t, msg) res := h(ctx, msg) - hasInvalidCategory := strings.Contains(res.Log, "801") - assert.True(t, hasInvalidCategory, "should return err code") + + assert.Equal(t, c.CodeInvalidCategory, res.Code) + assert.Equal(t, c.DefaultCodespace, res.Codespace) } func TestByzantineMsg(t *testing.T) { @@ -125,8 +125,8 @@ func TestByzantineMsg(t *testing.T) { fakeMsg := c.NewCreateCategoryMsg("title", sdk.AccAddress([]byte{1, 2}), "slug", "") res := h(ctx, fakeMsg) - hasUnrecognizedMessage := strings.Contains(res.Log, "65542") - assert.True(t, hasUnrecognizedMessage, "should return err code") + assert.Equal(t, sdk.CodeUnknownRequest, res.Code) + assert.Equal(t, sdk.CodespaceRoot, res.Codespace) } func TestFlagStoryMsg(t *testing.T) { diff --git a/x/story/keeper.go b/x/story/keeper.go index 81d5b431..fb6f4ceb 100644 --- a/x/story/keeper.go +++ b/x/story/keeper.go @@ -11,6 +11,11 @@ import ( amino "github.com/tendermint/go-amino" ) +const ( + // StoreKey is string representation of the store key for stories + StoreKey = "stories" +) + // ReadKeeper defines a module interface that facilitates read only access // to truchain data type ReadKeeper interface { diff --git a/x/truapi/handle_registration.go b/x/truapi/handle_registration.go index dd4c9620..02407b87 100644 --- a/x/truapi/handle_registration.go +++ b/x/truapi/handle_registration.go @@ -26,8 +26,8 @@ type RegistrationRequest struct { // RegistrationResponse is a JSON response body representing the result of registering a key type RegistrationResponse struct { Address string `json:"address"` - AccountNumber int64 `json:"account_number"` - Sequence int64 `json:"sequence"` + AccountNumber uint64 `json:"account_number"` + Sequence uint64 `json:"sequence"` Coins sdk.Coins `json:"coins"` } diff --git a/x/users/querier.go b/x/users/querier.go index a8bc8302..a6b90731 100644 --- a/x/users/querier.go +++ b/x/users/querier.go @@ -52,7 +52,7 @@ func queryUsersByAddresses( for i, a := range params.Addresses { addr, err := sdk.AccAddressFromBech32(a) if err != nil { - return res, sdk.NewError(0, 0, "Error decoding address: "+err.Error()) + return res, sdk.NewError("users", 0, "Error decoding address: "+err.Error()) } account := k.GetAccount(ctx, addr) if account != nil { diff --git a/x/users/types.go b/x/users/types.go index 20d3a249..c05ffbee 100644 --- a/x/users/types.go +++ b/x/users/types.go @@ -9,9 +9,9 @@ import ( // User is the externally-facing account object type User struct { Address string `json:"address"` - AccountNumber int64 `json:"account_number"` + AccountNumber uint64 `json:"account_number"` Coins sdk.Coins `json:"coins"` - Sequence int64 `json:"sequence"` + Sequence uint64 `json:"sequence"` Pubkey tcmn.HexBytes `json:"pubkey"` } diff --git a/x/vote/errors.go b/x/vote/errors.go index 3cffe932..6e67370a 100644 --- a/x/vote/errors.go +++ b/x/vote/errors.go @@ -10,7 +10,7 @@ import ( // Vote errors reserve 1100 ~ 1199. const ( - DefaultCodespace sdk.CodespaceType = 12 + DefaultCodespace sdk.CodespaceType = "vote" CodeNotFound sdk.CodeType = 1201 CodeDuplicate sdk.CodeType = 1202 diff --git a/x/vote/keeper.go b/x/vote/keeper.go index 3301e967..9822fc92 100644 --- a/x/vote/keeper.go +++ b/x/vote/keeper.go @@ -16,6 +16,11 @@ import ( amino "github.com/tendermint/go-amino" ) +const ( + // StoreKey is string representation of the store key for vote + StoreKey = "vote" +) + // ReadKeeper defines a module interface that facilitates read only access to truchain data type ReadKeeper interface { app.ReadKeeper diff --git a/x/vote/test_common.go b/x/vote/test_common.go index 09a8f654..08f8ecda 100644 --- a/x/vote/test_common.go +++ b/x/vote/test_common.go @@ -17,6 +17,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/params" amino "github.com/tendermint/go-amino" abci "github.com/tendermint/tendermint/abci/types" cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" @@ -28,16 +29,18 @@ func mockDB() (sdk.Context, Keeper, c.Keeper) { db := dbm.NewMemDB() - accKey := sdk.NewKVStoreKey("acc") - storyKey := sdk.NewKVStoreKey("stories") - catKey := sdk.NewKVStoreKey("categories") - challengeKey := sdk.NewKVStoreKey("challenges") - gameKey := sdk.NewKVStoreKey("games") - pendingGameListKey := sdk.NewKVStoreKey("pendingGameList") - gameQueueKey := sdk.NewKVStoreKey("gameQueue") - voteKey := sdk.NewKVStoreKey("vote") - backingKey := sdk.NewKVStoreKey("backing") - backingListKey := sdk.NewKVStoreKey("backingList") + accKey := sdk.NewKVStoreKey(auth.StoreKey) + storyKey := sdk.NewKVStoreKey(story.StoreKey) + catKey := sdk.NewKVStoreKey(c.StoreKey) + challengeKey := sdk.NewKVStoreKey(challenge.StoreKey) + gameKey := sdk.NewKVStoreKey(game.StoreKey) + pendingGameListKey := sdk.NewKVStoreKey(game.PendingListStoreKey) + gameQueueKey := sdk.NewKVStoreKey(game.QueueStoreKey) + voteKey := sdk.NewKVStoreKey(StoreKey) + backingKey := sdk.NewKVStoreKey(backing.StoreKey) + backingListKey := sdk.NewKVStoreKey(backing.ListStoreKey) + paramsKey := sdk.NewKVStoreKey(params.StoreKey) + transientParamsKey := sdk.NewTransientStoreKey(params.TStoreKey) ms := store.NewCommitMultiStore(db) ms.MountStoreWithDB(accKey, sdk.StoreTypeIAVL, db) @@ -60,7 +63,8 @@ func mockDB() (sdk.Context, Keeper, c.Keeper) { codec.RegisterInterface((*auth.Account)(nil), nil) codec.RegisterConcrete(&auth.BaseAccount{}, "auth/Account", nil) - am := auth.NewAccountKeeper(codec, accKey, auth.ProtoBaseAccount) + pk := params.NewKeeper(codec, paramsKey, transientParamsKey) + am := auth.NewAccountKeeper(codec, accKey, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) bankKeeper := bank.NewBaseKeeper(am) ck := c.NewKeeper(catKey, codec) sk := story.NewKeeper(storyKey, ck, codec) From 28b45c27901ead22774e908f8758cab445f6f3b7 Mon Sep 17 00:00:00 2001 From: jhernandezb Date: Tue, 5 Feb 2019 16:07:54 -0600 Subject: [PATCH 2/5] Fixed linting issues --- cmd/truchaind/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/truchaind/main.go b/cmd/truchaind/main.go index 3f30f5d0..a5106382 100644 --- a/cmd/truchaind/main.go +++ b/cmd/truchaind/main.go @@ -74,7 +74,7 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command { } nodeID := string(nodeKey.ID()) - // initalize files and upgrades priv_validator file format (< v0.28) + // initialize files and upgrades priv_validator file format (< v0.28) _, pk, err := gaiaInit.InitializeNodeValidatorFiles(config) if err != nil { return err From 85bb667313803d607efd7d3c7a22918928045b2f Mon Sep 17 00:00:00 2001 From: jhernandezb Date: Tue, 5 Feb 2019 17:19:17 -0600 Subject: [PATCH 3/5] Restored subtract implementation --- x/vote/tally_confirmed.go | 14 +++++++++++++- x/vote/tally_test.go | 11 +++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/x/vote/tally_confirmed.go b/x/vote/tally_confirmed.go index 2160e2da..9c4fe1e1 100644 --- a/x/vote/tally_confirmed.go +++ b/x/vote/tally_confirmed.go @@ -64,7 +64,9 @@ func distributeRewardsConfirmed( rewardCoin := sdk.NewCoin(pool.Denom, voterRewardAmount) // remove reward amount from pool - pool = pool.Minus(rewardCoin) + // TODO: using restored version of Minus in sdk v0.26.0 until issue #325 is resolved + // after finshed should be pool.Minus(rewardCoin) + pool = subtract(pool, rewardCoin) // payout user _, _, err = bankKeeper.AddCoins(ctx, v.Creator(), sdk.Coins{rewardCoin}) @@ -139,3 +141,13 @@ func voterRewardAmount(pool sdk.Coin, voterCount int64) sdk.Int { QuoInt(voterCountInt). RoundInt() } + +func subtract(coinA, coinB sdk.Coin) sdk.Coin { + if !coinA.SameDenomAs(coinB) { + return coinA + } + return sdk.Coin{ + Denom: coinA.Denom, + Amount: coinA.Amount.Sub(coinB.Amount), + } +} diff --git a/x/vote/tally_test.go b/x/vote/tally_test.go index 083c1ca8..fd7e1c05 100644 --- a/x/vote/tally_test.go +++ b/x/vote/tally_test.go @@ -244,3 +244,14 @@ func Test_voterRewardAmount(t *testing.T) { pool, _ := sdk.ParseCoin("1usecase") assert.Equal(t, sdk.NewInt(0), voterRewardAmount(pool, 0)) } + +func Test_subtract(t *testing.T) { + coinA, _ := sdk.ParseCoin("100usecase") + coinB, _ := sdk.ParseCoin("25usecase") + + result, _ := sdk.ParseCoin("75usecase") + assert.Equal(t, subtract(coinA, coinB), result) + + result.Amount = sdk.NewInt(-75) + assert.Equal(t, subtract(coinB, coinA), result) +} From ca2fac2b68ac02e347aabe2cf06decb4cbca8f23 Mon Sep 17 00:00:00 2001 From: jhernandezb Date: Wed, 6 Feb 2019 09:41:07 -0600 Subject: [PATCH 4/5] Fixed panic in NewUser when public key is nil --- x/users/types.go | 9 ++++++++- x/users/types_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 x/users/types_test.go diff --git a/x/users/types.go b/x/users/types.go index c05ffbee..57459d9b 100644 --- a/x/users/types.go +++ b/x/users/types.go @@ -17,11 +17,18 @@ type User struct { // NewUser creates a new User struct from an auth.Account (like AppAccount) func NewUser(acc auth.Account) User { + var pubKey []byte + + // GetPubKey can return nil and Bytes() will panic due to nil pointer + if acc.GetPubKey() != nil { + pubKey = acc.GetPubKey().Bytes() + } + return User{ Address: acc.GetAddress().String(), AccountNumber: acc.GetAccountNumber(), Coins: acc.GetCoins(), Sequence: acc.GetSequence(), - Pubkey: tcmn.HexBytes(acc.GetPubKey().Bytes()), + Pubkey: tcmn.HexBytes(pubKey), } } diff --git a/x/users/types_test.go b/x/users/types_test.go new file mode 100644 index 00000000..13e6985e --- /dev/null +++ b/x/users/types_test.go @@ -0,0 +1,26 @@ +package users + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/tendermint/tendermint/crypto/ed25519" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/stretchr/testify/assert" +) + +func Test_NewUserEmptyPublicKey(t *testing.T) { + // Check that NewUser don't panick by checking that recover() result is nil + defer func() { + assert.Nil(t, recover()) + }() + key := ed25519.GenPrivKey() + pub := key.PubKey() + addr := sdk.AccAddress(pub.Address()) + acc := auth.ProtoBaseAccount() + acc.SetAddress(addr) + user := NewUser(acc) + assert.Nil(t, user.Pubkey) +} From 975244f38c41cfc6bfd2078b85cdb83cb5defd1c Mon Sep 17 00:00:00 2001 From: jhernandezb Date: Wed, 6 Feb 2019 10:26:34 -0600 Subject: [PATCH 5/5] Updated tests --- x/backing/handler_test.go | 9 +++++++++ x/backing/msg_test.go | 11 ++++++----- x/vote/tally_test.go | 4 ++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/x/backing/handler_test.go b/x/backing/handler_test.go index decc22c3..ad88ef1e 100644 --- a/x/backing/handler_test.go +++ b/x/backing/handler_test.go @@ -72,3 +72,12 @@ func TestBackStoryMsg(t *testing.T) { assert.Equal(t, int64(1), idres.ID, "incorrect result backing id") } + +func TestByzantineMsg(t *testing.T) { + ctx, bk, _, _, _, _ := mockDB() + h := NewHandler(bk) + assert.NotNil(t, h) + res := h(ctx, nil) + assert.Equal(t, sdk.CodeUnknownRequest, res.Code) + assert.Equal(t, sdk.CodespaceRoot, res.Codespace) +} diff --git a/x/backing/msg_test.go b/x/backing/msg_test.go index a4032f3b..92f0019b 100644 --- a/x/backing/msg_test.go +++ b/x/backing/msg_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/TruStory/truchain/x/story" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" ) @@ -33,7 +34,7 @@ func TestInvalidStoryIdBackMsg(t *testing.T) { msg := NewBackStoryMsg(invalidStoryID, validStake, validArgument, validCreator, validPeriod) err := msg.ValidateBasic() - assert.Equal(t, sdk.CodeType(702), err.Code(), err.Error()) + assert.Equal(t, story.CodeInvalidStoryID, err.Code(), err.Error()) } func TestInvalidAddressBackMsg(t *testing.T) { @@ -45,7 +46,7 @@ func TestInvalidAddressBackMsg(t *testing.T) { msg := NewBackStoryMsg(validStoryID, validStake, validArgument, invalidCreator, validPeriod) err := msg.ValidateBasic() - assert.Equal(t, sdk.CodeType(7), err.Code(), err.Error()) + assert.Equal(t, sdk.CodeInvalidAddress, err.Code(), err.Error()) } func TestInValidStakeBackMsg(t *testing.T) { @@ -57,7 +58,7 @@ func TestInValidStakeBackMsg(t *testing.T) { msg := NewBackStoryMsg(validStoryID, invalidStake, validArgument, validCreator, validPeriod) err := msg.ValidateBasic() - assert.Equal(t, sdk.CodeType(5), err.Code(), err.Error()) + assert.Equal(t, sdk.CodeInsufficientFunds, err.Code(), err.Error()) } func TestInValidBackingPeriodBackMsg(t *testing.T) { @@ -69,7 +70,7 @@ func TestInValidBackingPeriodBackMsg(t *testing.T) { msg := NewBackStoryMsg(validStoryID, validStake, validArgument, validCreator, invalidPeriod) err := msg.ValidateBasic() - assert.Equal(t, sdk.CodeType(901), err.Code(), err.Error()) + assert.Equal(t, CodeInvalidPeriod, err.Code(), err.Error()) } func TestInValidBackingPeriod2BackMsg(t *testing.T) { @@ -81,5 +82,5 @@ func TestInValidBackingPeriod2BackMsg(t *testing.T) { msg := NewBackStoryMsg(validStoryID, validStake, validArgument, validCreator, invalidPeriod) err := msg.ValidateBasic() - assert.Equal(t, sdk.CodeType(901), err.Code(), err.Error()) + assert.Equal(t, CodeInvalidPeriod, err.Code(), err.Error()) } diff --git a/x/vote/tally_test.go b/x/vote/tally_test.go index fd7e1c05..d57275ca 100644 --- a/x/vote/tally_test.go +++ b/x/vote/tally_test.go @@ -254,4 +254,8 @@ func Test_subtract(t *testing.T) { result.Amount = sdk.NewInt(-75) assert.Equal(t, subtract(coinB, coinA), result) + + // If different coin type return coinA + coinC, _ := sdk.ParseCoin("25anotherusecase") + assert.Equal(t, subtract(coinA, coinC), coinA) }