From 3baae6ac095089aaa725a538f033a08a0ee8449a Mon Sep 17 00:00:00 2001 From: klim0v Date: Mon, 2 May 2022 18:12:00 +0300 Subject: [PATCH 01/48] optimization bestTrade skip smallPairs --- coreV2/state/swap/swapV2.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/coreV2/state/swap/swapV2.go b/coreV2/state/swap/swapV2.go index 676c5dba6..b047021dd 100644 --- a/coreV2/state/swap/swapV2.go +++ b/coreV2/state/swap/swapV2.go @@ -77,6 +77,8 @@ func (p *PairV2) Coin1() types.CoinID { return p.PairKey.Coin1 } +var smallPairs = map[uint32]struct{}{10: {}, 14: {}, 17: {}, 24: {}, 26: {}, 27: {}, 29: {}, 30: {}, 31: {}, 38: {}, 42: {}, 44: {}, 51: {}, 52: {}, 57: {}, 60: {}, 67: {}, 69: {}, 71: {}, 72: {}, 73: {}, 74: {}, 78: {}, 79: {}, 84: {}, 87: {}, 88: {}, 91: {}, 92: {}, 97: {}, 99: {}, 100: {}, 101: {}, 105: {}, 106: {}, 107: {}, 108: {}, 109: {}, 110: {}, 113: {}, 115: {}, 119: {}, 120: {}, 121: {}, 122: {}, 124: {}, 127: {}, 129: {}, 131: {}, 138: {}, 140: {}, 141: {}, 142: {}, 145: {}, 148: {}, 149: {}, 150: {}, 151: {}, 154: {}, 155: {}, 157: {}, 159: {}, 160: {}, 161: {}, 164: {}, 165: {}, 168: {}, 169: {}, 170: {}, 171: {}, 172: {}, 173: {}, 174: {}, 175: {}, 179: {}, 181: {}, 182: {}, 184: {}, 186: {}, 188: {}, 191: {}, 192: {}, 194: {}, 195: {}, 196: {}, 197: {}, 198: {}, 199: {}, 201: {}, 202: {}, 209: {}, 210: {}, 215: {}, 216: {}, 221: {}, 224: {}, 225: {}, 226: {}, 227: {}, 228: {}, 229: {}, 231: {}, 233: {}, 236: {}, 237: {}, 238: {}, 239: {}, 240: {}, 241: {}, 245: {}, 251: {}, 254: {}, 256: {}, 257: {}, 258: {}, 259: {}, 260: {}, 264: {}, 265: {}, 267: {}, 270: {}, 276: {}, 277: {}, 279: {}, 280: {}, 281: {}, 282: {}, 283: {}, 285: {}, 286: {}, 287: {}, 289: {}, 290: {}, 291: {}, 292: {}, 293: {}, 297: {}, 302: {}, 303: {}, 309: {}, 314: {}, 315: {}, 316: {}, 317: {}, 318: {}, 319: {}, 320: {}, 324: {}, 325: {}, 326: {}, 331: {}, 335: {}, 336: {}, 337: {}, 338: {}, 341: {}, 342: {}, 343: {}, 344: {}, 345: {}, 346: {}, 347: {}, 350: {}, 351: {}, 353: {}, 364: {}, 365: {}, 366: {}, 367: {}, 368: {}, 369: {}, 373: {}, 374: {}, 375: {}, 376: {}, 377: {}, 383: {}, 385: {}, 387: {}, 388: {}, 394: {}, 395: {}, 397: {}, 399: {}, 403: {}, 404: {}, 405: {}, 406: {}, 407: {}, 408: {}, 409: {}, 410: {}, 411: {}, 415: {}, 416: {}, 417: {}, 418: {}, 421: {}, 422: {}, 423: {}, 424: {}, 425: {}, 426: {}, 429: {}, 430: {}, 431: {}, 432: {}, 433: {}, 434: {}, 435: {}, 436: {}, 439: {}, 440: {}, 441: {}, 442: {}, 443: {}, 445: {}, 447: {}, 448: {}, 449: {}, 450: {}, 451: {}, 452: {}, 453: {}, 454: {}, 455: {}, 457: {}, 460: {}, 461: {}, 462: {}, 467: {}, 468: {}, 469: {}, 470: {}, 471: {}, 472: {}, 473: {}, 475: {}, 478: {}, 479: {}, 480: {}, 482: {}, 484: {}, 486: {}, 487: {}, 488: {}, 489: {}, 490: {}, 497: {}, 501: {}, 504: {}, 507: {}, 508: {}, 509: {}, 511: {}, 513: {}, 515: {}, 516: {}, 517: {}, 519: {}, 520: {}, 522: {}, 525: {}, 530: {}, 531: {}, 532: {}, 533: {}, 535: {}, 537: {}, 539: {}, 541: {}, 542: {}, 543: {}, 544: {}, 545: {}, 547: {}, 548: {}, 549: {}, 551: {}, 553: {}, 556: {}, 558: {}, 559: {}, 560: {}, 564: {}, 568: {}, 569: {}, 570: {}, 572: {}, 576: {}, 577: {}, 578: {}, 584: {}, 586: {}, 587: {}, 588: {}, 590: {}, 593: {}, 594: {}, 595: {}, 596: {}, 598: {}, 599: {}, 600: {}, 601: {}, 602: {}, 603: {}, 606: {}, 607: {}, 608: {}, 609: {}, 611: {}, 615: {}, 621: {}, 624: {}, 625: {}, 626: {}, 627: {}, 628: {}, 629: {}, 630: {}, 632: {}, 634: {}, 636: {}, 637: {}, 638: {}, 639: {}, 640: {}, 642: {}, 643: {}, 646: {}, 647: {}, 648: {}, 651: {}, 652: {}, 653: {}, 655: {}, 658: {}, 659: {}, 662: {}, 665: {}, 666: {}, 667: {}, 668: {}, 671: {}, 673: {}, 674: {}, 675: {}, 676: {}, 677: {}, 679: {}, 682: {}, 685: {}, 690: {}, 691: {}, 692: {}, 695: {}, 700: {}, 708: {}, 709: {}, 711: {}, 712: {}, 715: {}, 718: {}, 719: {}, 720: {}, 721: {}, 722: {}, 727: {}, 731: {}, 733: {}, 735: {}, 737: {}, 738: {}, 739: {}, 740: {}, 741: {}, 742: {}, 744: {}, 745: {}, 746: {}, 747: {}, 748: {}, 749: {}, 750: {}, 751: {}, 752: {}, 756: {}, 757: {}, 758: {}, 759: {}, 760: {}, 761: {}, 762: {}, 763: {}, 764: {}, 765: {}, 766: {}, 767: {}, 778: {}, 779: {}, 782: {}, 784: {}, 795: {}, 801: {}, 804: {}, 805: {}, 807: {}, 812: {}, 813: {}, 814: {}, 820: {}, 821: {}, 822: {}, 826: {}, 827: {}, 828: {}, 829: {}, 830: {}, 831: {}, 832: {}, 838: {}, 839: {}, 840: {}, 843: {}, 844: {}, 846: {}, 849: {}, 851: {}, 852: {}, 853: {}, 858: {}, 865: {}, 867: {}, 872: {}, 874: {}, 876: {}, 878: {}, 879: {}, 880: {}, 881: {}, 882: {}, 883: {}, 890: {}, 891: {}, 892: {}, 901: {}, 902: {}, 904: {}, 906: {}, 909: {}, 910: {}, 911: {}, 913: {}, 916: {}, 918: {}, 920: {}, 922: {}, 923: {}, 924: {}, 925: {}, 928: {}, 932: {}, 933: {}, 934: {}, 935: {}, 936: {}, 937: {}, 948: {}, 951: {}, 952: {}, 953: {}, 954: {}, 957: {}, 959: {}, 960: {}, 961: {}, 962: {}, 963: {}, 966: {}, 967: {}, 970: {}, 974: {}, 976: {}, 977: {}, 979: {}, 980: {}, 981: {}, 982: {}, 984: {}, 1005: {}, 1013: {}, 1014: {}, 1015: {}, 1022: {}, 1024: {}, 1025: {}, 1041: {}, 1043: {}, 1044: {}, 1048: {}, 1049: {}, 1050: {}, 1052: {}, 1058: {}, 1059: {}, 1062: {}, 1066: {}, 1067: {}, 1068: {}, 1069: {}, 1070: {}, 1071: {}, 1072: {}, 1073: {}, 1074: {}, 1075: {}, 1076: {}, 1077: {}, 1079: {}, 1084: {}, 1090: {}, 1091: {}, 1095: {}, 1096: {}, 1100: {}, 1103: {}, 1114: {}, 1116: {}, 1125: {}, 1126: {}, 1127: {}, 1128: {}, 1130: {}, 1131: {}, 1135: {}, 1136: {}, 1137: {}, 1140: {}, 1142: {}, 1143: {}, 1145: {}, 1151: {}, 1152: {}, 1153: {}, 1154: {}, 1155: {}, 1156: {}, 1157: {}, 1158: {}, 1159: {}, 1163: {}, 1164: {}, 1167: {}, 1170: {}, 1171: {}, 1172: {}, 1175: {}, 1176: {}, 1177: {}, 1181: {}, 1183: {}, 1185: {}, 1204: {}, 1205: {}, 1206: {}, 1211: {}, 1215: {}, 1221: {}, 1222: {}, 1223: {}, 1226: {}, 1228: {}, 1230: {}, 1236: {}, 1237: {}, 1238: {}, 1239: {}, 1253: {}, 1255: {}, 1266: {}, 1277: {}, 1287: {}} + func (s *SwapV2) swapPools(ctx context.Context) []EditableChecker { s.loadPools() @@ -92,6 +94,11 @@ func (s *SwapV2) swapPools(ctx context.Context) []EditableChecker { if pair == nil { continue } + + if _, ok := smallPairs[pair.GetID()]; ok { + continue + } + pools = append(pools, pair) select { From ce1b9b8dd63cfa4f1eefd1610ee4108b6a434c69 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 7 May 2022 19:54:27 +0300 Subject: [PATCH 02/48] update sync peers --- config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 9334b1113..d1e10ca3c 100644 --- a/config/config.go +++ b/config/config.go @@ -43,8 +43,8 @@ func DefaultConfig() *Config { "bab220855eb9625ea547f1ef1d11692c60a7a406@138.201.28.219:26656" cfg.P2P.PersistentPeers = - "bac66d7240caca750dfb78a1ebb0a82a7a5ba898@state-test.minter.network:26656," + - "5b877dcc33c780bf9ae9dfde9070c055832b72b5@sync-test.minter.network:26656," + + "2e34b2bbadeffb0a75214af2a914d9990d7f954d@state-test.minter.network:26656," + + "d694da084a87ac5ce86f31fb48e1efdc711d9cc1@sync-test.minter.network:26656," + "ddda6ce2626e6da6055bb32ebece2907c7997d3f@sync104.minter.su:26656," + "7e1c0be4cfbc99a7b81cb5566a3eb9832fff542f@sync101.minter.su:26656" From 85a796ea9c6cfda516f59553b2b2aa5233914736 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 7 May 2022 19:57:02 +0300 Subject: [PATCH 03/48] update sync peers --- config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index d1e10ca3c..5fa407af4 100644 --- a/config/config.go +++ b/config/config.go @@ -78,8 +78,8 @@ func DefaultConfig() *Config { //cfg.StateSync.RPCServers = []string{"sync-test.minter.network:26657", "sync104.minter.su:26657", "state-test.minter.network:26657"} cfg.StateSync.RPCServers = []string{"state-test.minter.network:26657", "sync-test.minter.network:26657", "sync101.minter.su:26657"} - cfg.StateSync.TrustHeight = 10309900 - cfg.StateSync.TrustHash = "95AB9C70AE7B98F955CB05039A3B2A442F3DA4F95FF82B027A8144AE0E15C6BF" + cfg.StateSync.TrustHeight = 10682290 + cfg.StateSync.TrustHash = "CC1E2F922FEAE855301CF0BBFD7BDBB340A75812A4B68D2ACBBE5F2DF8790561" cfg.StateSync.TrustPeriod = time.Hour * 8760 return cfg From 70b8d45eac26a7cdc318073e846816ab95f42268 Mon Sep 17 00:00:00 2001 From: klim0v Date: Wed, 11 May 2022 14:15:13 +0300 Subject: [PATCH 04/48] waitlists --- api/v2/service/waitlist.go | 50 +++++++++++++++++++++++++++++++ coreV2/state/waitlist/model.go | 4 +++ coreV2/state/waitlist/waitlist.go | 17 +++++++++++ go.mod | 2 +- go.sum | 4 +-- 5 files changed, 74 insertions(+), 3 deletions(-) diff --git a/api/v2/service/waitlist.go b/api/v2/service/waitlist.go index 252ed98f3..0f2fe03ef 100644 --- a/api/v2/service/waitlist.go +++ b/api/v2/service/waitlist.go @@ -11,6 +11,56 @@ import ( "strings" ) +// WaitLists returns the list stakes in waitlist. +func (s *Service) WaitLists(ctx context.Context, req *pb.WaitListsRequest) (*pb.WaitListsResponse, error) { + cState, err := s.blockchain.GetStateForHeight(req.Height) + if err != nil { + return nil, status.Error(codes.NotFound, err.Error()) + } + + if req.Height != 0 { + cState.Candidates().LoadCandidates() + } + + if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil { + return nil, timeoutStatus.Err() + } + + response := new(pb.WaitListsResponse) + + model := cState.WaitList().GetAll() + + if len(model) == 0 { + return response, nil + } + + response.Addresses = make([]*pb.WaitListsResponse_Address, 0, len(model)) + for _, items := range model { + addr := &pb.WaitListsResponse_Address{ + Address: items.Address().String(), + List: make([]*pb.WaitListsResponse_Address_Wait, 0, len(items.List)), + } + + for _, item := range items.List { + if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil { + return nil, timeoutStatus.Err() + } + + addr.List = append(addr.List, &pb.WaitListsResponse_Address_Wait{ + PublicKey: cState.Candidates().PubKey(item.CandidateId).String(), + Coin: &pb.Coin{ + Id: uint64(item.Coin), + Symbol: cState.Coins().GetCoin(item.Coin).GetFullSymbol(), + }, + Value: item.Value.String(), + }) + } + response.Addresses = append(response.Addresses, addr) + } + + return response, nil +} + // WaitList returns the list of address stakes in waitlist. func (s *Service) WaitList(ctx context.Context, req *pb.WaitListRequest) (*pb.WaitListResponse, error) { if !strings.HasPrefix(strings.Title(req.Address), "Mx") { diff --git a/coreV2/state/waitlist/model.go b/coreV2/state/waitlist/model.go index 428df8240..834ca3284 100644 --- a/coreV2/state/waitlist/model.go +++ b/coreV2/state/waitlist/model.go @@ -20,6 +20,10 @@ type Model struct { lock sync.RWMutex } +func (m *Model) Address() types.Address { + return m.address +} + func (m *Model) AddToList(candidateId uint32, coin types.CoinID, value *big.Int) { m.lock.Lock() defer m.lock.Unlock() diff --git a/coreV2/state/waitlist/waitlist.go b/coreV2/state/waitlist/waitlist.go index 00891c56d..8a2898225 100644 --- a/coreV2/state/waitlist/waitlist.go +++ b/coreV2/state/waitlist/waitlist.go @@ -23,6 +23,7 @@ type RWaitList interface { Get(address types.Address, pubkey types.Pubkey, coin types.CoinID) *Item GetByAddress(address types.Address) *Model + GetAll() []*Model GetByAddressAndPubKey(address types.Address, pubkey types.Pubkey) []*Item Export(state *types.AppState) } @@ -162,6 +163,22 @@ func (wl *WaitList) Commit(db *iavl.MutableTree, version int64) error { func (wl *WaitList) GetByAddress(address types.Address) *Model { return wl.get(address) } +func (wl *WaitList) GetAll() (waitlists []*Model) { + wl.immutableTree().IterateRange([]byte{mainPrefix}, []byte{mainPrefix + 1}, true, func(key []byte, value []byte) bool { + address := types.BytesToAddress(key[1:]) + + model := &Model{address: address} + if err := rlp.DecodeBytes(value, model); err != nil { + panic(fmt.Sprintf("failed to decode waitlists for address %s: %s", address.String(), err)) + } + + waitlists = append(waitlists, model) + + return false + }) + + return waitlists +} func (wl *WaitList) Get(address types.Address, pubkey types.Pubkey, coin types.CoinID) *Item { waitlist := wl.get(address) diff --git a/go.mod b/go.mod index 5377b8c2e..178cd057e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/MinterTeam/minter-go-node go 1.17 require ( - github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220413090743-53ffbb191668 + github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220511110553-8e89c773113f github.com/btcsuite/btcd v0.22.0-beta github.com/c-bata/go-prompt v0.2.5 github.com/cosmos/cosmos-sdk v0.44.5 diff --git a/go.sum b/go.sum index b80daf54d..d6c6968ec 100644 --- a/go.sum +++ b/go.sum @@ -85,8 +85,8 @@ github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jB github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY= github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= -github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220413090743-53ffbb191668 h1:uqMIMMMXAYs6Vrlw0oX0UaN3DrlWh4iGVm3QahAxZbc= -github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220413090743-53ffbb191668/go.mod h1:aXWn+ewPqPGbnHbKEZzNik3motgWpFkT7LFTcBWvlHI= +github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220511110553-8e89c773113f h1:CeFKcVffOlbBdQTDsZ7qhRXGaDFQy2xAu0sfF4d47c4= +github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220511110553-8e89c773113f/go.mod h1:aXWn+ewPqPGbnHbKEZzNik3motgWpFkT7LFTcBWvlHI= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= From 49a8ae3bbbc1713e1e50552a5ddd74883fd30d20 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 13 May 2022 10:52:19 +0300 Subject: [PATCH 05/48] testnet fix --- coreV2/minter/blockchain.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coreV2/minter/blockchain.go b/coreV2/minter/blockchain.go index ae7147d7c..c626bc772 100644 --- a/coreV2/minter/blockchain.go +++ b/coreV2/minter/blockchain.go @@ -454,8 +454,8 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes. var moreRewards = big.NewInt(0) if height%blockchain.updateStakesAndPayRewardsPeriod == 0 { PayRewards := blockchain.stateDeliver.Validators.PayRewardsV3 - if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h { - if height < h+blockchain.updateStakesAndPayRewardsPeriod { + if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h || types.CurrentChainID == types.ChainTestnet { + if height < h+blockchain.updateStakesAndPayRewardsPeriod && types.CurrentChainID == types.ChainMainnet { excess := blockchain.stateDeliver.Candidates.FixStakesAfter10509400() blockchain.appDB.SetEmission(big.NewInt(0).Sub(blockchain.appDB.Emission(), excess)) log.Println("fixEmission", blockchain.appDB.Emission()) From abb86e18ff0ea87e47f22c11dea46fb8b8348906 Mon Sep 17 00:00:00 2001 From: klim0v Date: Mon, 16 May 2022 11:40:41 +0300 Subject: [PATCH 06/48] tx tags --- coreV2/transaction/add_liquidity.go | 2 +- coreV2/transaction/add_liquidity_v240.go | 2 +- coreV2/transaction/add_liquidity_v260.go | 2 +- coreV2/transaction/add_order.go | 4 ++-- coreV2/transaction/remove_limit_order.go | 3 ++- coreV2/transaction/remove_liquidity_v1.go | 2 +- coreV2/transaction/remove_liquidity_v230.go | 2 +- coreV2/transaction/remove_liquidity_v240.go | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/coreV2/transaction/add_liquidity.go b/coreV2/transaction/add_liquidity.go index bb8dcbae6..ae854b7af 100644 --- a/coreV2/transaction/add_liquidity.go +++ b/coreV2/transaction/add_liquidity.go @@ -185,7 +185,7 @@ func (data AddLiquidityDataV1) Run(tx *Transaction, context state.Interface, rew {Key: []byte("tx.liquidity"), Value: []byte(liquidity.String())}, {Key: []byte("tx.pool_token"), Value: []byte(coinLiquidity.GetFullSymbol()), Index: true}, {Key: []byte("tx.pool_token_id"), Value: []byte(coinLiquidity.ID().String()), Index: true}, - {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1))}, + {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1)), Index: true}, {Key: []byte("tx.pool_id"), Value: []byte(types.CoinID(swapper.GetID()).String()), Index: true}, } } diff --git a/coreV2/transaction/add_liquidity_v240.go b/coreV2/transaction/add_liquidity_v240.go index 4afb5f48c..f68d0f89e 100644 --- a/coreV2/transaction/add_liquidity_v240.go +++ b/coreV2/transaction/add_liquidity_v240.go @@ -223,7 +223,7 @@ func (data AddLiquidityDataV240) Run(tx *Transaction, context state.Interface, r {Key: []byte("tx.liquidity"), Value: []byte(liquidity.String())}, {Key: []byte("tx.pool_token"), Value: []byte(coinLiquidity.GetFullSymbol()), Index: true}, {Key: []byte("tx.pool_token_id"), Value: []byte(coinLiquidity.ID().String()), Index: true}, - {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1))}, + {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1)), Index: true}, {Key: []byte("tx.pool_id"), Value: []byte(types.CoinID(swapper.GetID()).String()), Index: true}, } } diff --git a/coreV2/transaction/add_liquidity_v260.go b/coreV2/transaction/add_liquidity_v260.go index dc14a2f27..d45b579c4 100644 --- a/coreV2/transaction/add_liquidity_v260.go +++ b/coreV2/transaction/add_liquidity_v260.go @@ -224,7 +224,7 @@ func (data AddLiquidityDataV260) Run(tx *Transaction, context state.Interface, r {Key: []byte("tx.liquidity"), Value: []byte(liquidity.String())}, {Key: []byte("tx.pool_token"), Value: []byte(coinLiquidity.GetFullSymbol()), Index: true}, {Key: []byte("tx.pool_token_id"), Value: []byte(coinLiquidity.ID().String()), Index: true}, - {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1))}, + {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1)), Index: true}, {Key: []byte("tx.pool_id"), Value: []byte(types.CoinID(swapper.GetID()).String()), Index: true}, } } diff --git a/coreV2/transaction/add_order.go b/coreV2/transaction/add_order.go index 642b90c77..7fc768081 100644 --- a/coreV2/transaction/add_order.go +++ b/coreV2/transaction/add_order.go @@ -182,8 +182,8 @@ func (data AddLimitOrderData) Run(tx *Transaction, context state.Interface, rewa {Key: []byte("tx.commission_conversion"), Value: []byte(isGasCommissionFromPoolSwap.String()), Index: true}, {Key: []byte("tx.commission_amount"), Value: []byte(commission.String())}, {Key: []byte("tx.commission_details"), Value: []byte(tagsCom.string())}, - {Key: []byte("tx.pool_id"), Value: []byte(strconv.Itoa(int(poolID)))}, - {Key: []byte("tx.order_id"), Value: []byte(strconv.Itoa(int(orderID)))}, + {Key: []byte("tx.pool_id"), Value: []byte(strconv.Itoa(int(poolID))), Index: true}, + {Key: []byte("tx.order_id"), Value: []byte(strconv.Itoa(int(orderID))), Index: true}, } } diff --git a/coreV2/transaction/remove_limit_order.go b/coreV2/transaction/remove_limit_order.go index a59e37bf4..7dad3a645 100644 --- a/coreV2/transaction/remove_limit_order.go +++ b/coreV2/transaction/remove_limit_order.go @@ -150,7 +150,8 @@ func (data RemoveLimitOrderData) Run(tx *Transaction, context state.Interface, r {Key: []byte("tx.commission_amount"), Value: []byte(commission.String())}, {Key: []byte("tx.commission_details"), Value: []byte(tagsCom.string())}, {Key: []byte("tx.order_id"), Value: []byte(strconv.Itoa(int(data.ID))), Index: true}, - {Key: []byte("tx.pair_id"), Value: []byte(strconv.Itoa(int(swapper.GetID()))), Index: true}, + {Key: []byte("tx.pool_id"), Value: []byte(strconv.Itoa(int(swapper.GetID()))), Index: true}, + {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(swapper.Coin0(), swapper.Coin1())), Index: true}, } } diff --git a/coreV2/transaction/remove_liquidity_v1.go b/coreV2/transaction/remove_liquidity_v1.go index bf8f951d0..7f3f8af45 100644 --- a/coreV2/transaction/remove_liquidity_v1.go +++ b/coreV2/transaction/remove_liquidity_v1.go @@ -157,7 +157,7 @@ func (data RemoveLiquidityV1) Run(tx *Transaction, context state.Interface, rewa {Key: []byte("tx.volume1"), Value: []byte(amount1.String())}, {Key: []byte("tx.pool_token"), Value: []byte(coinLiquidity.GetFullSymbol()), Index: true}, {Key: []byte("tx.pool_token_id"), Value: []byte(coinLiquidity.ID().String()), Index: true}, - {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1))}, + {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1)), Index: true}, {Key: []byte("tx.pool_id"), Value: []byte(types.CoinID(swapper.GetID()).String()), Index: true}, } } diff --git a/coreV2/transaction/remove_liquidity_v230.go b/coreV2/transaction/remove_liquidity_v230.go index 67b6d6b0b..521f4e43b 100644 --- a/coreV2/transaction/remove_liquidity_v230.go +++ b/coreV2/transaction/remove_liquidity_v230.go @@ -182,7 +182,7 @@ func (data RemoveLiquidityV230) Run(tx *Transaction, context state.Interface, re {Key: []byte("tx.volume1"), Value: []byte(amount1.String())}, {Key: []byte("tx.pool_token"), Value: []byte(coinLiquidity.GetFullSymbol()), Index: true}, {Key: []byte("tx.pool_token_id"), Value: []byte(coinLiquidity.ID().String()), Index: true}, - {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1))}, + {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1)), Index: true}, {Key: []byte("tx.pool_id"), Value: []byte(types.CoinID(swapper.GetID()).String()), Index: true}, } } diff --git a/coreV2/transaction/remove_liquidity_v240.go b/coreV2/transaction/remove_liquidity_v240.go index 8f4ec7261..1de551d20 100644 --- a/coreV2/transaction/remove_liquidity_v240.go +++ b/coreV2/transaction/remove_liquidity_v240.go @@ -183,7 +183,7 @@ func (data RemoveLiquidityV240) Run(tx *Transaction, context state.Interface, re {Key: []byte("tx.pool_token"), Value: []byte(coinLiquidity.GetFullSymbol()), Index: true}, {Key: []byte("tx.pool_token_id"), Value: []byte(coinLiquidity.ID().String()), Index: true}, {Key: []byte("tx.commission_details"), Value: []byte(tagsCom.string())}, - {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1))}, + {Key: []byte("tx.pair_ids"), Value: []byte(liquidityCoinName(data.Coin0, data.Coin1)), Index: true}, {Key: []byte("tx.pool_id"), Value: []byte(types.CoinID(swapper.GetID()).String()), Index: true}, } } From 46c5905a0a014f01c875e06319cf495fd8407acc Mon Sep 17 00:00:00 2001 From: klim0v Date: Mon, 16 May 2022 11:44:39 +0300 Subject: [PATCH 07/48] testnet --- coreV2/minter/blockchain.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/coreV2/minter/blockchain.go b/coreV2/minter/blockchain.go index c626bc772..581d602b9 100644 --- a/coreV2/minter/blockchain.go +++ b/coreV2/minter/blockchain.go @@ -454,18 +454,29 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes. var moreRewards = big.NewInt(0) if height%blockchain.updateStakesAndPayRewardsPeriod == 0 { PayRewards := blockchain.stateDeliver.Validators.PayRewardsV3 - if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h || types.CurrentChainID == types.ChainTestnet { - if height < h+blockchain.updateStakesAndPayRewardsPeriod && types.CurrentChainID == types.ChainMainnet { - excess := blockchain.stateDeliver.Candidates.FixStakesAfter10509400() - blockchain.appDB.SetEmission(big.NewInt(0).Sub(blockchain.appDB.Emission(), excess)) - log.Println("fixEmission", blockchain.appDB.Emission()) + if types.CurrentChainID == types.ChainTestnet { + if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix + } else if h := blockchain.appDB.GetVersionHeight(V320); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix + } else if h := blockchain.appDB.GetVersionHeight(V310); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV4 + } + } else { + if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h { + if height < h+blockchain.updateStakesAndPayRewardsPeriod { + excess := blockchain.stateDeliver.Candidates.FixStakesAfter10509400() + blockchain.appDB.SetEmission(big.NewInt(0).Sub(blockchain.appDB.Emission(), excess)) + log.Println("fixEmission", blockchain.appDB.Emission()) + } + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix + } else if h := blockchain.appDB.GetVersionHeight(V320); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Bug + } else if h := blockchain.appDB.GetVersionHeight(V310); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV4 } - PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix - } else if h := blockchain.appDB.GetVersionHeight(V320); h > 0 && height > h { - PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Bug - } else if h := blockchain.appDB.GetVersionHeight(V310); h > 0 && height > h { - PayRewards = blockchain.stateDeliver.Validators.PayRewardsV4 } + moreRewards = PayRewards(heightIsMaxIfIssueIsOverOrNotDynamic, int64(blockchain.updateStakesAndPayRewardsPeriod)) blockchain.appDB.SetEmission(big.NewInt(0).Add(blockchain.appDB.Emission(), moreRewards)) blockchain.stateDeliver.Checker.AddCoinVolume(types.GetBaseCoinID(), moreRewards) From 7bb33c59d9dfdc434417dc202244494f9fba987f Mon Sep 17 00:00:00 2001 From: klim0v Date: Mon, 16 May 2022 11:46:48 +0300 Subject: [PATCH 08/48] version --- version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/version.go b/version/version.go index 4d6633307..e0f055ef5 100755 --- a/version/version.go +++ b/version/version.go @@ -7,7 +7,7 @@ const ( var ( // Version must be a string because scripts like dist.sh read this file. - Version = "3.3.0" + Version = "3.3.1" // GitCommit is the current HEAD set using ldflags. GitCommit string From 5247d9998ffb458480ef6154b4d0b820e3cfc1a8 Mon Sep 17 00:00:00 2001 From: klim0v Date: Mon, 16 May 2022 12:12:38 +0300 Subject: [PATCH 09/48] Subscribe --- api/v2/service/subscribe.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/v2/service/subscribe.go b/api/v2/service/subscribe.go index e70021654..a5a5fef8b 100644 --- a/api/v2/service/subscribe.go +++ b/api/v2/service/subscribe.go @@ -39,7 +39,8 @@ func (s *Service) Subscribe(request *pb.SubscribeRequest, stream pb.ApiService_S } }() - ctxSubscribeConnection, _ := context.WithTimeout(stream.Context(), s.minterCfg.WSConnectionDuration) + ctxSubscribeConnection, cancel2 := context.WithTimeout(stream.Context(), s.minterCfg.WSConnectionDuration) + defer cancel2() for { select { From bb042fe875ad9345076ff17b4e6be127e8426d2e Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 20 May 2022 23:02:40 +0300 Subject: [PATCH 10/48] load_last_events cmd --- api/v2/service/block.go | 248 +++++++++++++++-------------- cmd/minter/cmd/load_last_events.go | 54 +++++++ cmd/minter/main.go | 1 + 3 files changed, 183 insertions(+), 120 deletions(-) create mode 100644 cmd/minter/cmd/load_last_events.go diff --git a/api/v2/service/block.go b/api/v2/service/block.go index ee06d2c78..02510919a 100644 --- a/api/v2/service/block.go +++ b/api/v2/service/block.go @@ -82,126 +82,8 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes if req.Events { loadEvents := s.blockchain.GetEventsDB().LoadEvents(uint32(req.Height)) for _, event := range loadEvents { - var m proto.Message - switch e := event.(type) { - case *events.JailEvent: - m = &pb.JailEvent{ - ValidatorPubKey: e.ValidatorPubKeyString(), - JailedUntil: e.JailedUntil, - } - case *events.OrderExpiredEvent: - m = &pb.OrderExpiredEvent{ - Id: e.ID, - Address: e.AddressString(), - Coin: e.Coin, - Amount: e.Amount, - } - case *events.RewardEvent: - m = &pb.RewardEvent{ - Role: pb.RewardEvent_Role(pb.RewardEvent_Role_value[e.Role]), - Address: e.AddressString(), - Amount: e.Amount, - ForCoin: e.ForCoin, - ValidatorPubKey: e.ValidatorPubKeyString(), - } - case *events.SlashEvent: - m = &pb.SlashEvent{ - Address: e.AddressString(), - Amount: e.Amount, - Coin: e.Coin, - ValidatorPubKey: e.ValidatorPubKeyString(), - } - case *events.StakeKickEvent: - m = &pb.StakeKickEvent{ - Address: e.AddressString(), - Amount: e.Amount, - Coin: e.Coin, - ValidatorPubKey: e.ValidatorPubKeyString(), - } - case *events.UnbondEvent: - m = &pb.UnbondEvent{ - Address: e.AddressString(), - Amount: e.Amount, - Coin: e.Coin, - ValidatorPubKey: e.ValidatorPubKeyString(), - } - case *events.UnlockEvent: - m = &pb.UnlockEvent{ - Address: e.AddressString(), - Amount: e.Amount, - Coin: e.Coin, - } - case *events.StakeMoveEvent: - m = &pb.StakeMoveEvent{ - Address: e.AddressString(), - Amount: e.Amount, - Coin: e.Coin, - CandidatePubKey: e.CandidatePubKey.String(), - ToCandidatePubKey: e.ToCandidatePubKey.String(), - } - case *events.RemoveCandidateEvent: - m = &pb.RemoveCandidateEvent{ - CandidatePubKey: e.CandidatePubKeyString(), - } - case *events.UpdateNetworkEvent: - m = &pb.UpdateNetworkEvent{ - Version: e.Version, - } - case *events.UpdatedBlockRewardEvent: - m = &pb.UpdatedBlockRewardEvent{ - Value: e.Value, - ValueLockedStakeRewards: e.ValueLockedStakeRewards, - } - case *events.UpdateCommissionsEvent: - m = &pb.UpdateCommissionsEvent{ - Coin: e.Coin, - PayloadByte: e.PayloadByte, - Send: e.Send, - BuyBancor: e.BuyBancor, - SellBancor: e.SellBancor, - SellAllBancor: e.SellAllBancor, - BuyPoolBase: e.BuyPoolBase, - BuyPoolDelta: e.BuyPoolDelta, - SellPoolBase: e.SellPoolBase, - SellPoolDelta: e.SellPoolDelta, - SellAllPoolBase: e.SellAllPoolBase, - SellAllPoolDelta: e.SellAllPoolDelta, - CreateTicker3: e.CreateTicker3, - CreateTicker4: e.CreateTicker4, - CreateTicker5: e.CreateTicker5, - CreateTicker6: e.CreateTicker6, - CreateTicker7_10: e.CreateTicker7_10, - CreateCoin: e.CreateCoin, - CreateToken: e.CreateToken, - RecreateCoin: e.RecreateCoin, - RecreateToken: e.RecreateToken, - DeclareCandidacy: e.DeclareCandidacy, - Delegate: e.Delegate, - Unbond: e.Unbond, - RedeemCheck: e.RedeemCheck, - SetCandidateOn: e.SetCandidateOn, - SetCandidateOff: e.SetCandidateOff, - CreateMultisig: e.CreateMultisig, - MultisendBase: e.MultisendBase, - MultisendDelta: e.MultisendDelta, - EditCandidate: e.EditCandidate, - SetHaltBlock: e.SetHaltBlock, - EditTickerOwner: e.EditTickerOwner, - EditMultisig: e.EditMultisig, - EditCandidatePublicKey: e.EditCandidatePublicKey, - CreateSwapPool: e.CreateSwapPool, - AddLiquidity: e.AddLiquidity, - RemoveLiquidity: e.RemoveLiquidity, - EditCandidateCommission: e.EditCandidateCommission, - MintToken: e.MintToken, - BurnToken: e.BurnToken, - VoteCommission: e.VoteCommission, - VoteUpdate: e.VoteUpdate, - FailedTx: e.FailedTx, - AddLimitOrder: e.AddLimitOrder, - RemoveLimitOrder: e.RemoveLimitOrder, - } - default: + m := DecodeEvent(event) + if m == nil { return nil, status.Error(codes.Internal, "unknown event type") } @@ -258,6 +140,132 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes return response, nil } +func DecodeEvent(event events.Event) proto.Message { + var m proto.Message + switch e := event.(type) { + case *events.JailEvent: + m = &pb.JailEvent{ + ValidatorPubKey: e.ValidatorPubKeyString(), + JailedUntil: e.JailedUntil, + } + case *events.OrderExpiredEvent: + m = &pb.OrderExpiredEvent{ + Id: e.ID, + Address: e.AddressString(), + Coin: e.Coin, + Amount: e.Amount, + } + case *events.RewardEvent: + m = &pb.RewardEvent{ + Role: pb.RewardEvent_Role(pb.RewardEvent_Role_value[e.Role]), + Address: e.AddressString(), + Amount: e.Amount, + ForCoin: e.ForCoin, + ValidatorPubKey: e.ValidatorPubKeyString(), + } + case *events.SlashEvent: + m = &pb.SlashEvent{ + Address: e.AddressString(), + Amount: e.Amount, + Coin: e.Coin, + ValidatorPubKey: e.ValidatorPubKeyString(), + } + case *events.StakeKickEvent: + m = &pb.StakeKickEvent{ + Address: e.AddressString(), + Amount: e.Amount, + Coin: e.Coin, + ValidatorPubKey: e.ValidatorPubKeyString(), + } + case *events.UnbondEvent: + m = &pb.UnbondEvent{ + Address: e.AddressString(), + Amount: e.Amount, + Coin: e.Coin, + ValidatorPubKey: e.ValidatorPubKeyString(), + } + case *events.UnlockEvent: + m = &pb.UnlockEvent{ + Address: e.AddressString(), + Amount: e.Amount, + Coin: e.Coin, + } + case *events.StakeMoveEvent: + m = &pb.StakeMoveEvent{ + Address: e.AddressString(), + Amount: e.Amount, + Coin: e.Coin, + CandidatePubKey: e.CandidatePubKey.String(), + ToCandidatePubKey: e.ToCandidatePubKey.String(), + } + case *events.RemoveCandidateEvent: + m = &pb.RemoveCandidateEvent{ + CandidatePubKey: e.CandidatePubKeyString(), + } + case *events.UpdateNetworkEvent: + m = &pb.UpdateNetworkEvent{ + Version: e.Version, + } + case *events.UpdatedBlockRewardEvent: + m = &pb.UpdatedBlockRewardEvent{ + Value: e.Value, + ValueLockedStakeRewards: e.ValueLockedStakeRewards, + } + case *events.UpdateCommissionsEvent: + m = &pb.UpdateCommissionsEvent{ + Coin: e.Coin, + PayloadByte: e.PayloadByte, + Send: e.Send, + BuyBancor: e.BuyBancor, + SellBancor: e.SellBancor, + SellAllBancor: e.SellAllBancor, + BuyPoolBase: e.BuyPoolBase, + BuyPoolDelta: e.BuyPoolDelta, + SellPoolBase: e.SellPoolBase, + SellPoolDelta: e.SellPoolDelta, + SellAllPoolBase: e.SellAllPoolBase, + SellAllPoolDelta: e.SellAllPoolDelta, + CreateTicker3: e.CreateTicker3, + CreateTicker4: e.CreateTicker4, + CreateTicker5: e.CreateTicker5, + CreateTicker6: e.CreateTicker6, + CreateTicker7_10: e.CreateTicker7_10, + CreateCoin: e.CreateCoin, + CreateToken: e.CreateToken, + RecreateCoin: e.RecreateCoin, + RecreateToken: e.RecreateToken, + DeclareCandidacy: e.DeclareCandidacy, + Delegate: e.Delegate, + Unbond: e.Unbond, + RedeemCheck: e.RedeemCheck, + SetCandidateOn: e.SetCandidateOn, + SetCandidateOff: e.SetCandidateOff, + CreateMultisig: e.CreateMultisig, + MultisendBase: e.MultisendBase, + MultisendDelta: e.MultisendDelta, + EditCandidate: e.EditCandidate, + SetHaltBlock: e.SetHaltBlock, + EditTickerOwner: e.EditTickerOwner, + EditMultisig: e.EditMultisig, + EditCandidatePublicKey: e.EditCandidatePublicKey, + CreateSwapPool: e.CreateSwapPool, + AddLiquidity: e.AddLiquidity, + RemoveLiquidity: e.RemoveLiquidity, + EditCandidateCommission: e.EditCandidateCommission, + MintToken: e.MintToken, + BurnToken: e.BurnToken, + VoteCommission: e.VoteCommission, + VoteUpdate: e.VoteUpdate, + FailedTx: e.FailedTx, + AddLimitOrder: e.AddLimitOrder, + RemoveLimitOrder: e.RemoveLimitOrder, + } + default: + return nil + } + return m +} + func blockEvidence(block *core_types.ResultBlock) (*pb.BlockResponse_Evidence, error) { evidences := make([]*_struct.Struct, 0, len(block.Block.Evidence.Evidence)) for _, evidence := range block.Block.Evidence.Evidence { diff --git a/cmd/minter/cmd/load_last_events.go b/cmd/minter/cmd/load_last_events.go new file mode 100644 index 000000000..b8546447c --- /dev/null +++ b/cmd/minter/cmd/load_last_events.go @@ -0,0 +1,54 @@ +package cmd + +import ( + "fmt" + "github.com/MinterTeam/minter-go-node/api/v2/service" + "github.com/MinterTeam/minter-go-node/cmd/utils" + "github.com/MinterTeam/minter-go-node/coreV2/appdb" + eventsdb "github.com/MinterTeam/minter-go-node/coreV2/events" + "github.com/MinterTeam/minter-go-node/coreV2/minter" + "github.com/spf13/cobra" +) + +var ( + LoadLastEventsCommand = &cobra.Command{ + Use: "load_last_events", + Short: "Minter debug last events", + RunE: getLastEvents, + } +) + +func getLastEvents(cmd *cobra.Command, args []string) error { + homeDir, err := cmd.Flags().GetString("home-dir") + if err != nil { + return err + } + storages := utils.NewStorage(homeDir, "") + + _, err = storages.InitEventLevelDB("data/events", minter.GetDbOpts(1024)) + if err != nil { + return err + } + + eventsDB := eventsdb.NewEventsStore(storages.EventDB()) + + db := appdb.NewAppDB(storages.GetMinterHome(), cfg) + height := uint32(db.GetLastHeight()) + events := eventsDB.LoadEvents(height) + + fmt.Println("height", height) + for _, event := range events { + fmt.Printf("%s %v\n", event.Type(), service.DecodeEvent(event)) + } + //ldb, err := storages.InitStateLevelDB("data/state", nil) + //if err != nil { + // log.Panicf("Cannot load db: %s", err) + //} + + //currentState, err := state.NewCheckStateAtHeightV3(height, ldb) + //if err != nil { + // log.Panicf("Cannot new state at given height: %s, last available height %d", err, db.GetLastHeight()) + //} + + return nil +} diff --git a/cmd/minter/main.go b/cmd/minter/main.go index 87ee0c06d..84329d4df 100644 --- a/cmd/minter/main.go +++ b/cmd/minter/main.go @@ -28,6 +28,7 @@ func main() { cmd.VerifyGenesis, cmd.Version, cmd.ExportCommand, + cmd.LoadLastEventsCommand, ) rootCmd.PersistentFlags().String("home-dir", "", "base dir (default is $HOME/.minter)") From 38328ce2de12e2d6f923a785dea9acb5f0515c84 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 20 May 2022 23:21:25 +0300 Subject: [PATCH 11/48] only-api-mode --- cmd/minter/cmd/node.go | 21 ++++++++++++++------- cmd/minter/main.go | 2 ++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/minter/cmd/node.go b/cmd/minter/cmd/node.go index ed3eeb100..be94df9a4 100644 --- a/cmd/minter/cmd/node.go +++ b/cmd/minter/cmd/node.go @@ -108,6 +108,20 @@ func runNode(cmd *cobra.Command) error { // start TM node node := startTendermintNode(app, tmConfig, logger, storages.GetMinterHome()) + isOnlyApiMode, err := cmd.Flags().GetBool("only-api-mode") + if err != nil { + return err + } + + if isOnlyApiMode { + logger.With("module", "node").Info("Started only API") + } else { + if err = node.Start(); err != nil { + logger.Error("failed to start node", "err", err) + return err + } + logger.With("module", "node").Info("Started node", "node", node.Switch().NodeInfo()) + } client := app.RpcClient() if !cfg.ValidatorMode { @@ -243,13 +257,6 @@ func startTendermintNode(app *minter.Blockchain, cfg *tmCfg.Config, logger tmLog app.SetTmNode(node) - if err = node.Start(); err != nil { - logger.Error("failed to start node", "err", err) - os.Exit(1) - } - - logger.Info("Started node", "nodeInfo", node.Switch().NodeInfo()) - return node } diff --git a/cmd/minter/main.go b/cmd/minter/main.go index 84329d4df..93802603f 100644 --- a/cmd/minter/main.go +++ b/cmd/minter/main.go @@ -40,6 +40,8 @@ func main() { rootCmd.PersistentFlags().String("persistent-peers", "", "") rootCmd.PersistentFlags().Bool("state-sync", false, "enable state sync snapshots") + cmd.RunNode.PersistentFlags().Bool("only-api-mode", false, "enable API only") + cmd.ExportCommand.Flags().Uint64("height", 0, "export height") cmd.ExportCommand.Flags().Bool("indent", false, "using indent") cmd.ExportCommand.Flags().String("chain-id", "", "export chain id") From 43555c755cbb1261e4f10a02d603794155e4ad00 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 20 May 2022 23:53:28 +0300 Subject: [PATCH 12/48] only-api-mode --- cmd/minter/cmd/node.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/minter/cmd/node.go b/cmd/minter/cmd/node.go index be94df9a4..3109e5941 100644 --- a/cmd/minter/cmd/node.go +++ b/cmd/minter/cmd/node.go @@ -105,17 +105,18 @@ func runNode(cmd *cobra.Command) error { app.SetSnapshotStore(snapshotStore, cfg.SnapshotInterval, cfg.SnapshotKeepRecent) } - // start TM node - node := startTendermintNode(app, tmConfig, logger, storages.GetMinterHome()) - isOnlyApiMode, err := cmd.Flags().GetBool("only-api-mode") if err != nil { return err } + var node *tmNode.Node if isOnlyApiMode { + tmConfig.StateSync.Enable = true + node = startTendermintNode(app, tmConfig, logger, storages.GetMinterHome()+"/mock") logger.With("module", "node").Info("Started only API") - } else { + } else { // start TM node + node = startTendermintNode(app, tmConfig, logger, storages.GetMinterHome()) if err = node.Start(); err != nil { logger.Error("failed to start node", "err", err) return err @@ -124,7 +125,7 @@ func runNode(cmd *cobra.Command) error { } client := app.RpcClient() - if !cfg.ValidatorMode { + if !cfg.ValidatorMode || isOnlyApiMode { runAPI(logger, app, client, node, app.RewardCounter()) } From 0ff550e6e2a47302e536740b79c8dd08b3271adc Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 21 May 2022 00:59:16 +0300 Subject: [PATCH 13/48] only-api-mode --- cmd/minter/cmd/node.go | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/cmd/minter/cmd/node.go b/cmd/minter/cmd/node.go index 3109e5941..20423ed22 100644 --- a/cmd/minter/cmd/node.go +++ b/cmd/minter/cmd/node.go @@ -23,13 +23,17 @@ import ( "github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/proxy" rpc "github.com/tendermint/tendermint/rpc/client/local" + sm "github.com/tendermint/tendermint/state" + "github.com/tendermint/tendermint/store" tmTypes "github.com/tendermint/tendermint/types" "io" "net/http" _ "net/http/pprof" // nolint: gosec // securely exposed on separate, optional port "net/url" "os" + "reflect" "syscall" + "unsafe" ) // RunNode is the command that allows the CLI to start a node. @@ -113,8 +117,39 @@ func runNode(cmd *cobra.Command) error { var node *tmNode.Node if isOnlyApiMode { tmConfig.StateSync.Enable = true - node = startTendermintNode(app, tmConfig, logger, storages.GetMinterHome()+"/mock") - logger.With("module", "node").Info("Started only API") + blockStoreDB, err := tmNode.DefaultDBProvider(&tmNode.DBContext{ID: "blockstore", Config: tmConfig}) + if err != nil { + panic(err) + } + blockStore := store.NewBlockStore(blockStoreDB) + + stateDB, err := tmNode.DefaultDBProvider(&tmNode.DBContext{ID: "state", Config: tmConfig}) + if err != nil { + panic(err) + } + stateStore := sm.NewStore(stateDB) + + tmConfig.DBBackend = "memdb" + node = startTendermintNode(app, tmConfig, logger, storages.GetMinterHome()) + + { + member := reflect.ValueOf(node).Elem().FieldByName("blockStore") + ptrToY := unsafe.Pointer(member.UnsafeAddr()) + realPtrToY := (**store.BlockStore)(ptrToY) + *realPtrToY = blockStore + } + + { + member := reflect.ValueOf(node).Elem().FieldByName("stateStore") + ptrToY := unsafe.Pointer(member.UnsafeAddr()) + realPtrToY := (*sm.Store)(ptrToY) + *realPtrToY = stateStore + } + err = node.ConfigureRPC() + if err != nil { + panic(err) + } + logger.With("module", "node").Info("Started only API", "last_height", blockStore.Height()) } else { // start TM node node = startTendermintNode(app, tmConfig, logger, storages.GetMinterHome()) if err = node.Start(); err != nil { From 6b2cd56e9da63d83f4d064da5044bda99e227c12 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 21 May 2022 13:15:30 +0300 Subject: [PATCH 14/48] fix deletedCandidates --- api/v2/service/candidates.go | 11 ++++++ coreV2/state/candidates/candidates.go | 50 +++++++++++++++++++++------ go.mod | 2 +- go.sum | 4 +-- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/api/v2/service/candidates.go b/api/v2/service/candidates.go index adad02e33..84c409ba6 100644 --- a/api/v2/service/candidates.go +++ b/api/v2/service/candidates.go @@ -30,6 +30,17 @@ func (s *Service) Candidates(ctx context.Context, req *pb.CandidatesRequest) (*p candidates := cState.Candidates().GetCandidates() response := &pb.CandidatesResponse{} + if req.Status == pb.CandidatesRequest_all || req.Status == pb.CandidatesRequest_deleted { + for _, dc := range cState.Candidates().DeletedCandidates() { + response.Deleted = append(response.Deleted, &pb.CandidatesResponse_Deleted{ + Id: uint64(dc.ID), + PublicKey: dc.PubKey.String(), + }) + } + } + if req.Status == pb.CandidatesRequest_deleted { + return response, nil + } for _, candidate := range candidates { if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil { diff --git a/coreV2/state/candidates/candidates.go b/coreV2/state/candidates/candidates.go index 1d5d39e58..d257748f3 100644 --- a/coreV2/state/candidates/candidates.go +++ b/coreV2/state/candidates/candidates.go @@ -49,7 +49,7 @@ var ( type RCandidates interface { // Deprecated ExportV1(state *types.AppState, height uint64, validators []*types.Candidate) []uint32 - + DeletedCandidates() (result []*deletedID) Export(state *types.AppState) Exists(pubkey types.Pubkey) bool IsBlockedPubKey(pubkey types.Pubkey) bool @@ -95,7 +95,7 @@ type Candidates struct { type deletedID struct { ID uint32 - PybKey types.Pubkey + PubKey types.Pubkey isDirty bool } @@ -161,9 +161,13 @@ func (c *Candidates) SetDeletedCandidates(list []types.DeletedCandidate) { c.dirtyDeletedCandidates = true for _, deleted := range list { + id := uint32(deleted.ID) + //if c.maxID < id { // TODO: FIXME + // c.maxID = id + //} c.deletedCandidates[deleted.PubKey] = &deletedID{ - ID: uint32(deleted.ID), - PybKey: deleted.PubKey, + ID: id, + PubKey: deleted.PubKey, isDirty: true, } } @@ -258,6 +262,9 @@ func (c *Candidates) Commit(db *iavl.MutableTree, version int64) error { } sort.Slice(deletedCandidates, func(i, j int) bool { + if deletedCandidates[i].ID == deletedCandidates[j].ID { + return deletedCandidates[i].PubKey.String() < deletedCandidates[j].PubKey.String() + } return deletedCandidates[i].ID < deletedCandidates[j].ID }) @@ -1131,14 +1138,37 @@ func (c *Candidates) Export(state *types.AppState) { for _, c := range c.deletedCandidates { state.DeletedCandidates = append(state.DeletedCandidates, types.DeletedCandidate{ ID: uint64(c.ID), - PubKey: c.PybKey, + PubKey: c.PubKey, }) } sort.SliceStable(state.DeletedCandidates, func(i, j int) bool { + if state.DeletedCandidates[i].ID == state.DeletedCandidates[j].ID { + return state.DeletedCandidates[i].PubKey.String() < state.DeletedCandidates[j].PubKey.String() + } return state.DeletedCandidates[i].ID < state.DeletedCandidates[j].ID }) } +func (c *Candidates) DeletedCandidates() (result []*deletedID) { + c.muDeletedCandidates.Lock() + defer c.muDeletedCandidates.Unlock() + + c.loadDeletedCandidates() + for _, c := range c.deletedCandidates { + result = append(result, &deletedID{ + ID: c.ID, + PubKey: c.PubKey, + }) + } + sort.SliceStable(result, func(i, j int) bool { + if result[i].ID == result[j].ID { + return result[i].PubKey.String() < result[j].PubKey.String() + } + return result[i].ID < result[j].ID + }) + return result +} + // Deprecated: Use getOrderedCandidatesLessID func (c *Candidates) getOrderedCandidates() []*Candidate { c.lock.RLock() @@ -1381,7 +1411,7 @@ func (c *Candidates) PubKey(id uint32) types.Pubkey { c.loadDeletedCandidates() for pubkey, d := range c.deletedCandidates { - if d.ID == id { + if d.ID == id { // todo: FIXME return pubkey } } @@ -1467,19 +1497,19 @@ func (c *Candidates) DeleteCandidate(height uint64, candidate *Candidate) { } c.lock.Lock() - c.deleteCandaditeFromList(candidate) + c.deleteCandidateFromList(candidate) c.totalStakes.Sub(c.totalStakes, candidate.totalBipStake) c.lock.Unlock() } -func (c *Candidates) deleteCandaditeFromList(candidate *Candidate) { +func (c *Candidates) deleteCandidateFromList(candidate *Candidate) { c.muDeletedCandidates.Lock() defer c.muDeletedCandidates.Unlock() c.loadDeletedCandidates() c.deletedCandidates[candidate.PubKey] = &deletedID{ ID: candidate.ID, - PybKey: candidate.PubKey, + PubKey: candidate.PubKey, isDirty: true, } c.dirtyDeletedCandidates = true @@ -1508,7 +1538,7 @@ func (c *Candidates) loadDeletedCandidates() { } for _, id := range list { - c.deletedCandidates[id.PybKey] = id + c.deletedCandidates[id.PubKey] = id } } diff --git a/go.mod b/go.mod index 178cd057e..917bd8b1f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/MinterTeam/minter-go-node go 1.17 require ( - github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220511110553-8e89c773113f + github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220521100308-a6e3f89cfa42 github.com/btcsuite/btcd v0.22.0-beta github.com/c-bata/go-prompt v0.2.5 github.com/cosmos/cosmos-sdk v0.44.5 diff --git a/go.sum b/go.sum index d6c6968ec..a8473741f 100644 --- a/go.sum +++ b/go.sum @@ -85,8 +85,8 @@ github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jB github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY= github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= -github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220511110553-8e89c773113f h1:CeFKcVffOlbBdQTDsZ7qhRXGaDFQy2xAu0sfF4d47c4= -github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220511110553-8e89c773113f/go.mod h1:aXWn+ewPqPGbnHbKEZzNik3motgWpFkT7LFTcBWvlHI= +github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220521100308-a6e3f89cfa42 h1:05lQGVNDMxRGhndk1V/Txdm5ATzVlzNmwJOAhUl1XU4= +github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220521100308-a6e3f89cfa42/go.mod h1:aXWn+ewPqPGbnHbKEZzNik3motgWpFkT7LFTcBWvlHI= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= From 8ff9f94537e5fb4a7c0fae69a495e7cf2409f336 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 21 May 2022 13:52:30 +0300 Subject: [PATCH 15/48] fix emission --- coreV2/appdb/appdb.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coreV2/appdb/appdb.go b/coreV2/appdb/appdb.go index e95f2378b..55e45803d 100644 --- a/coreV2/appdb/appdb.go +++ b/coreV2/appdb/appdb.go @@ -407,11 +407,12 @@ func (appDB *AppDB) SetEmission(emission *big.Int) { appDB.mu.Lock() defer appDB.mu.Unlock() + appDB.isDirtyEmission = true appDB.emission = emission } func (appDB *AppDB) SaveEmission() { - if appDB.isDirtyPrice == false { + if appDB.isDirtyEmission == false { return } From 469adce4db41e91ee986e6e53a1764632c517ad8 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 21 May 2022 13:59:50 +0300 Subject: [PATCH 16/48] fix emission --- coreV2/appdb/appdb.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/coreV2/appdb/appdb.go b/coreV2/appdb/appdb.go index 55e45803d..0fd84f82c 100644 --- a/coreV2/appdb/appdb.go +++ b/coreV2/appdb/appdb.go @@ -415,6 +415,7 @@ func (appDB *AppDB) SaveEmission() { if appDB.isDirtyEmission == false { return } + appDB.isDirtyEmission = false appDB.WG.Wait() if err := appDB.db.Set([]byte(emissionPath), appDB.emission.Bytes()); err != nil { @@ -554,6 +555,7 @@ func (appDB *AppDB) SavePrice() { if appDB.isDirtyPrice == false { return } + appDB.isDirtyPrice = false appDB.WG.Wait() From b18196b02c3a143eac76af2f42428b413e8a3998 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 21 May 2022 19:36:17 +0300 Subject: [PATCH 17/48] update --- coreV2/state/candidates/candidates.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/coreV2/state/candidates/candidates.go b/coreV2/state/candidates/candidates.go index d257748f3..e6fa517fb 100644 --- a/coreV2/state/candidates/candidates.go +++ b/coreV2/state/candidates/candidates.go @@ -263,7 +263,7 @@ func (c *Candidates) Commit(db *iavl.MutableTree, version int64) error { sort.Slice(deletedCandidates, func(i, j int) bool { if deletedCandidates[i].ID == deletedCandidates[j].ID { - return deletedCandidates[i].PubKey.String() < deletedCandidates[j].PubKey.String() + return deletedCandidates[i].PubKey.String() > deletedCandidates[j].PubKey.String() } return deletedCandidates[i].ID < deletedCandidates[j].ID }) @@ -1143,7 +1143,7 @@ func (c *Candidates) Export(state *types.AppState) { } sort.SliceStable(state.DeletedCandidates, func(i, j int) bool { if state.DeletedCandidates[i].ID == state.DeletedCandidates[j].ID { - return state.DeletedCandidates[i].PubKey.String() < state.DeletedCandidates[j].PubKey.String() + return state.DeletedCandidates[i].PubKey.String() > state.DeletedCandidates[j].PubKey.String() } return state.DeletedCandidates[i].ID < state.DeletedCandidates[j].ID }) @@ -1162,7 +1162,7 @@ func (c *Candidates) DeletedCandidates() (result []*deletedID) { } sort.SliceStable(result, func(i, j int) bool { if result[i].ID == result[j].ID { - return result[i].PubKey.String() < result[j].PubKey.String() + return result[i].PubKey.String() > result[j].PubKey.String() } return result[i].ID < result[j].ID }) From 42fd2a89714b0f143fbf6ce381b77affcc4042ef Mon Sep 17 00:00:00 2001 From: klim0v Date: Tue, 24 May 2022 20:26:46 +0300 Subject: [PATCH 18/48] fix message sell MinimumValueToBuyReached error --- coreV2/transaction/buy_swap_pool_v260.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreV2/transaction/buy_swap_pool_v260.go b/coreV2/transaction/buy_swap_pool_v260.go index 8fcf81abd..d187bd94c 100644 --- a/coreV2/transaction/buy_swap_pool_v260.go +++ b/coreV2/transaction/buy_swap_pool_v260.go @@ -318,7 +318,7 @@ func CheckSwap(rSwap swap.EditableChecker, coinIn CalculateCoin, coinOut Calcula Log: fmt.Sprintf( "You wanted to buy minimum %s %s, but currently you buy only %s %s", valueOut.String(), symbolOut, calculatedAmountToBuy.String(), symbolOut), - Info: EncodeError(code.NewMinimumValueToBuyReached(valueOut.String(), calculatedAmountToBuy.String(), coinIn.GetFullSymbol(), coinIn.ID().String())), + Info: EncodeError(code.NewMinimumValueToBuyReached(valueOut.String(), calculatedAmountToBuy.String(), coinOut.GetFullSymbol(), coinOut.ID().String())), }, nil, orders } valueOut = calculatedAmountToBuy From ba0f32467525afea5d3bb2bf84355df6edc3c76b Mon Sep 17 00:00:00 2001 From: klim0v Date: Mon, 30 May 2022 21:16:20 +0300 Subject: [PATCH 19/48] wip: tests --- coreV2/minter/minter_test.go | 82 ++++++++++++++++++++--- coreV2/state/accounts/accounts_test.go | 4 +- coreV2/state/candidates/candidate_test.go | 2 +- coreV2/transaction/buy_coin_test.go | 6 ++ tests/candidates_test.go | 10 +-- tests/emission_test.go | 4 +- tests/failed_test.go | 26 +++---- tests/reward3_test.go | 4 +- tests/swap3_test.go | 8 +-- tests/votes_test.go | 11 +-- 10 files changed, 112 insertions(+), 45 deletions(-) diff --git a/coreV2/minter/minter_test.go b/coreV2/minter/minter_test.go index 729862d15..2f78e0326 100644 --- a/coreV2/minter/minter_test.go +++ b/coreV2/minter/minter_test.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/MinterTeam/minter-go-node/coreV2/state/coins" "math/big" "testing" "time" @@ -126,9 +127,10 @@ func TestBlockchain_UpdateCommission(t *testing.T) { t.Fatal(err) } - data := transaction.VoteCommissionDataV1{ + data := transaction.VoteCommissionDataV3{ PubKey: types.BytesToPubkey(pv.Key.PubKey.Bytes()[:]), Height: 110, + Coin: 0, PayloadByte: helpers.StringToBigInt("200000000000000000"), Send: helpers.StringToBigInt("1000000000000000000"), BuyBancor: helpers.StringToBigInt("10000000000000000000"), @@ -171,11 +173,17 @@ func TestBlockchain_UpdateCommission(t *testing.T) { BurnToken: helpers.StringToBigInt("10000000000000000000"), VoteCommission: helpers.StringToBigInt("100000000000000000000"), VoteUpdate: helpers.StringToBigInt("100000000000000000000"), - More: []*big.Int{ - helpers.StringToBigInt("1000000000000000000"), - helpers.StringToBigInt("1000000000000000000"), - helpers.StringToBigInt("1000000000000000000"), - }, + FailedTx: helpers.StringToBigInt("1000000000000000000"), + AddLimitOrder: helpers.StringToBigInt("1000000000000000000"), + RemoveLimitOrder: helpers.StringToBigInt("1000000000000000000"), + MoveStake: helpers.StringToBigInt("1000000000000000000"), + LockStake: helpers.StringToBigInt("1000000000000000000"), + Lock: helpers.StringToBigInt("1000000000000000000"), + //More: []*big.Int{ + // helpers.StringToBigInt("1000000000000000000"), + // helpers.StringToBigInt("1000000000000000000"), + // helpers.StringToBigInt("1000000000000000000"), + //}, } encodedData, err := rlp.EncodeToBytes(data) @@ -409,6 +417,7 @@ func TestBlockchain_SetStatisticData(t *testing.T) { } func TestBlockchain_IsApplicationHalted(t *testing.T) { + t.Skip("todo") blockchain, tmCli, pv, cancel := initTestNode(t, 0) defer cancel() // unexpected call to os.Exit(0) during test data := transaction.SetHaltBlockData{ @@ -1018,8 +1027,21 @@ func getTestGenesis(pv *privval.FilePV, home string, initialState int64) func() validators, candidates := makeTestValidatorsAndCandidates([]string{string(pv.Key.PubKey.Bytes()[:])}, helpers.BipToPip(big.NewInt(12444011))) appState := types.AppState{ - Version: V3, - TotalSlashed: "0", + Note: "", + Validators: validators, + Candidates: candidates, + BlockListCandidates: nil, + DeletedCandidates: nil, + Waitlist: nil, + Pools: []types.Pool{{ + Coin0: 0, + Coin1: 1993, + Reserve0: "350000000000000000000000000000000", + Reserve1: "1000000000000000000000000000000", + ID: 1, + Orders: nil, + }}, + NextOrderID: 0, Accounts: []types.Account{ { Address: crypto.PubkeyToAddress(getPrivateKey().PublicKey), @@ -1028,11 +1050,28 @@ func getTestGenesis(pv *privval.FilePV, home string, initialState int64) func() Coin: uint64(types.GetBaseCoinID()), Value: helpers.BipToPip(big.NewInt(9223372036854775807)).String(), }, + { + Coin: uint64(types.USDTID), + Value: "1000000000000000000000000000000", + }, }, }, }, - Validators: validators, - Candidates: candidates, + Coins: []types.Coin{{ + ID: 1993, + Name: "USDT Eth", + Symbol: types.StrToCoinSymbol("USDTE"), + Volume: "2000000000000000000000000000000", + Crr: 0, + Reserve: "0", + MaxSupply: coins.MaxCoinSupply().String(), + Version: 0, + OwnerAddress: nil, + Mintable: false, + Burnable: false, + }}, + FrozenFunds: nil, + HaltBlocks: nil, Commission: types.Commission{ Coin: 0, PayloadByte: "2000000000000000", @@ -1073,11 +1112,32 @@ func getTestGenesis(pv *privval.FilePV, home string, initialState int64) func() AddLiquidity: "100000000000000000", RemoveLiquidity: "100000000000000000", EditCandidateCommission: "10000000000000000000", - BurnToken: "100000000000000000", MintToken: "100000000000000000", + BurnToken: "100000000000000000", VoteCommission: "1000000000000000000", VoteUpdate: "1000000000000000000", + FailedTx: "10000000000000000", + AddLimitOrder: "10000000000000000", + RemoveLimitOrder: "10000000000000000", + MoveStake: "10000000000000000", + LockStake: "10000000000000000", + Lock: "10000000000000000", + }, + CommissionVotes: nil, + UpdateVotes: nil, + UsedChecks: nil, + MaxGas: 0, + TotalSlashed: "0", + Emission: "1111", + PrevReward: types.RewardPrice{ + Time: 0, + AmountBIP: "350", + AmountUSDT: "1", + Off: false, + Reward: "79", }, + Version: V3, + Versions: nil, } appStateJSON, err := tmjson.Marshal(appState) diff --git a/coreV2/state/accounts/accounts_test.go b/coreV2/state/accounts/accounts_test.go index 8f7a6e65f..3dfc2ebeb 100644 --- a/coreV2/state/accounts/accounts_test.go +++ b/coreV2/state/accounts/accounts_test.go @@ -287,7 +287,7 @@ func TestAccounts_Commit(t *testing.T) { t.Fatalf("version %d", version) } - if fmt.Sprintf("%X", hash) != "8DAE826A26BD8A994B690BD6587A7852B3A75586A1A7162B97479A0D618774EF" { + if fmt.Sprintf("%X", hash) != "FB6DA65ECF998BC4050192B95E33B3A1B7319E88BD83D434D18F2A28EADC3217" { t.Fatalf("hash %X", hash) } } @@ -337,7 +337,7 @@ func TestAccounts_Export(t *testing.T) { t.Fatal(err) } - valid := "[{\"address\":\"Mx0400000000000000000000000000000000000000\",\"balance\":[{\"coin\":0,\"value\":\"1000\"},{\"coin\":1,\"value\":\"1001\"}],\"nonce\":0,\"multisig_data\":{\"weights\":[1,1,2],\"threshold\":2,\"addresses\":[\"Mx0100000000000000000000000000000000000000\",\"Mx0200000000000000000000000000000000000000\",\"Mx0300000000000000000000000000000000000000\"]},\"lock_stake_until_block\":0}]" + valid := "[{\"address\":\"Mx0400000000000000000000000000000000000000\",\"balance\":[{\"value\":\"1000\"},{\"coin\":1,\"value\":\"1001\"}],\"nonce\":0,\"multisig_data\":{\"weights\":[1,1,2],\"threshold\":2,\"addresses\":[\"Mx0100000000000000000000000000000000000000\",\"Mx0200000000000000000000000000000000000000\",\"Mx0300000000000000000000000000000000000000\"]}}]" if string(bytes) != valid { t.Log(string(bytes)) t.Log(valid) diff --git a/coreV2/state/candidates/candidate_test.go b/coreV2/state/candidates/candidate_test.go index 5d8f03c01..de3f9bace 100644 --- a/coreV2/state/candidates/candidate_test.go +++ b/coreV2/state/candidates/candidate_test.go @@ -537,7 +537,7 @@ func TestCandidates_Export(t *testing.T) { t.Fatal(err) } - valid := "[{\"id\":1,\"reward_address\":\"Mx0200000000000000000000000000000000000000\",\"owner_address\":\"Mx0100000000000000000000000000000000000000\",\"control_address\":\"Mx0300000000000000000000000000000000000000\",\"total_bip_stake\":\"200\",\"public_key\":\"Mp0400000000000000000000000000000000000000000000000000000000000000\",\"commission\":10,\"stakes\":[{\"owner\":\"Mx0100000000000000000000000000000000000000\",\"coin\":0,\"value\":\"100\",\"bip_value\":\"100\"},{\"owner\":\"Mx0200000000000000000000000000000000000000\",\"coin\":0,\"value\":\"100\",\"bip_value\":\"100\"}],\"status\":1}]" + valid := "[{\"id\":1,\"reward_address\":\"Mx0200000000000000000000000000000000000000\",\"owner_address\":\"Mx0100000000000000000000000000000000000000\",\"control_address\":\"Mx0300000000000000000000000000000000000000\",\"total_bip_stake\":\"200\",\"public_key\":\"Mp0400000000000000000000000000000000000000000000000000000000000000\",\"commission\":10,\"stakes\":[{\"owner\":\"Mx0100000000000000000000000000000000000000\",\"value\":\"100\",\"bip_value\":\"100\"},{\"owner\":\"Mx0200000000000000000000000000000000000000\",\"value\":\"100\",\"bip_value\":\"100\"}],\"status\":1}]" if string(bytes) != valid { t.Log(valid) t.Log(string(bytes)) diff --git a/coreV2/transaction/buy_coin_test.go b/coreV2/transaction/buy_coin_test.go index d2c68db81..28117106f 100644 --- a/coreV2/transaction/buy_coin_test.go +++ b/coreV2/transaction/buy_coin_test.go @@ -72,6 +72,12 @@ var ( MintToken: helpers.StringToBigInt("100000000000000000"), VoteCommission: helpers.StringToBigInt("1000000000000000000"), VoteUpdate: helpers.StringToBigInt("1000000000000000000"), + FailedTx: helpers.StringToBigInt("10000000000000000"), + AddLimitOrder: helpers.StringToBigInt("10000000000000000"), + RemoveLimitOrder: helpers.StringToBigInt("10000000000000000"), + MoveStake: helpers.StringToBigInt("10000000000000000"), + LockStake: helpers.StringToBigInt("10000000000000000"), + Lock: helpers.StringToBigInt("10000000000000000"), More: nil, } ) diff --git a/tests/candidates_test.go b/tests/candidates_test.go index 9c26a4ef1..01cd6982b 100644 --- a/tests/candidates_test.go +++ b/tests/candidates_test.go @@ -12,7 +12,7 @@ import ( func TestRemoveCandidate(t *testing.T) { state := DefaultAppState() // generate default state - state.Version = "v260" + state.Version = "v300" for i := byte(1); i < 255; i++ { @@ -104,7 +104,7 @@ func TestRemoveCandidate(t *testing.T) { func TestRemoveCandidate1(t *testing.T) { state := DefaultAppState() // generate default state - state.Version = "v260" + state.Version = "v300" stake := helpers.BipToPip(big.NewInt(10000)).String() @@ -194,7 +194,7 @@ func TestRemoveCandidate1(t *testing.T) { func TestRemoveCandidate2(t *testing.T) { state := DefaultAppState() // generate default state - state.Version = "v260" + state.Version = "v300" stake := helpers.BipToPip(big.NewInt(10000)).String() @@ -284,7 +284,7 @@ func TestRemoveCandidate2(t *testing.T) { func TestRemoveCandidate4(t *testing.T) { state := DefaultAppState() // generate default state - state.Version = "v260" + state.Version = "v300" stake := helpers.BipToPip(big.NewInt(10000)).String() @@ -374,7 +374,7 @@ func TestRemoveCandidate4(t *testing.T) { func TestRemoveCandidate5(t *testing.T) { state := DefaultAppState() // generate default state - state.Version = "v260" + state.Version = "v300" stake := helpers.BipToPip(big.NewInt(10000)).String() diff --git a/tests/emission_test.go b/tests/emission_test.go index cda9e4892..5265c9142 100644 --- a/tests/emission_test.go +++ b/tests/emission_test.go @@ -91,8 +91,8 @@ func TestLock_Emission(t *testing.T) { SendEndBlock(app, initialHeight) // send EndBlock SendCommit(app) // send Commit - if _, ok := app.CurrentState().Swap().(*swap.Swap); !ok { - t.Error("swap required v1") + if _, ok := app.CurrentState().Swap().(*swap.SwapV2); !ok { + t.Error("swap required v2") } SendBeginBlock(app, initialHeight+1) // send BeginBlock diff --git a/tests/failed_test.go b/tests/failed_test.go index efeced409..f69701ece 100644 --- a/tests/failed_test.go +++ b/tests/failed_test.go @@ -14,7 +14,7 @@ func TestFailedTxPayCommission(t *testing.T) { state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, Name: "aaa", @@ -104,7 +104,7 @@ func TestFailedTxPayCommission_customPriceCoin(t *testing.T) { state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, @@ -198,7 +198,7 @@ func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin_lessAvailable(t *te state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, @@ -292,7 +292,7 @@ func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin_lessAvailable_withG state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, @@ -386,7 +386,7 @@ func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin_withGasPrice(t *tes state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, @@ -479,7 +479,7 @@ func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin(t *testing.T) { state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, @@ -572,7 +572,7 @@ func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionToken(t *testin state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, @@ -702,7 +702,7 @@ func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionToken_withGasPr state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, @@ -832,7 +832,7 @@ func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionToken_withGasPr state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, @@ -962,7 +962,7 @@ func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCo state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, @@ -1075,7 +1075,7 @@ func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCo state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, @@ -1188,7 +1188,7 @@ func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCo state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, @@ -1311,7 +1311,7 @@ func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCo state := DefaultAppState() // generate default state - state.Version = "v250" + state.Version = "v300" state.Coins = append(state.Coins, types.Coin{ ID: 1, diff --git a/tests/reward3_test.go b/tests/reward3_test.go index 3bee0007a..e3dd1758d 100644 --- a/tests/reward3_test.go +++ b/tests/reward3_test.go @@ -53,7 +53,7 @@ func TestReward_Simple(t *testing.T) { Votes: []types.Pubkey{ [32]byte{1}, }, - Version: "v300", + Version: "v310", }, } state.Coins = []types.Coin{ @@ -97,7 +97,7 @@ func TestReward_Simple(t *testing.T) { SendCommit(app) // send Commit t.Log(app.UpdateVersions()[1]) - t.Log(app.GetEventsDB().LoadEvents(11)[0]) + //t.Log(app.GetEventsDB().LoadEvents(11)[0]) t.Log(app.CurrentState().App().Reward()) } diff --git a/tests/swap3_test.go b/tests/swap3_test.go index b2b589db0..0b0870baa 100644 --- a/tests/swap3_test.go +++ b/tests/swap3_test.go @@ -144,7 +144,7 @@ func TestSwap3_BuyGas0(t *testing.T) { SendCommit(app) // send Commit t.Log(app.UpdateVersions()[1]) - t.Log(app.GetEventsDB().LoadEvents(11)[0]) + //t.Log(app.GetEventsDB().LoadEvents(11)[0]) SendBeginBlock(app, 12) // send BeginBlock { @@ -322,7 +322,7 @@ func TestSwap3_BuyGas1(t *testing.T) { SendCommit(app) // send Commit t.Log(app.UpdateVersions()[1]) - t.Log(app.GetEventsDB().LoadEvents(11)[0]) + //t.Log(app.GetEventsDB().LoadEvents(11)[0]) SendBeginBlock(app, 12) // send BeginBlock { @@ -517,7 +517,7 @@ func TestSwap3_SellGas0(t *testing.T) { SendCommit(app) // send Commit t.Log(app.UpdateVersions()[1]) - t.Log(app.GetEventsDB().LoadEvents(11)[0]) + //t.Log(app.GetEventsDB().LoadEvents(11)[0]) SendBeginBlock(app, 12) // send BeginBlock { @@ -716,7 +716,7 @@ func TestSwap3_SellGas0_2(t *testing.T) { SendCommit(app) // send Commit t.Log(app.UpdateVersions()[1]) - t.Log(app.GetEventsDB().LoadEvents(11)[0]) + //t.Log(app.GetEventsDB().LoadEvents(11)[0]) SendBeginBlock(app, 12) // send BeginBlock { diff --git a/tests/votes_test.go b/tests/votes_test.go index ac3d91e21..dabd5ab92 100644 --- a/tests/votes_test.go +++ b/tests/votes_test.go @@ -26,7 +26,7 @@ func TestVoteupdate(t *testing.T) { address6 := crypto.PubkeyToAddress(privateKey6.PublicKey) state := DefaultAppState() // generate default state - state.Version = "v230" + state.Version = "v300" // add address to genesis state state.Accounts = append(state.Accounts, types.Account{ @@ -342,6 +342,7 @@ func TestVoteupdate(t *testing.T) { } func TestVoteCommissionFail(t *testing.T) { + t.Skip() privateKey1, _ := crypto.GenerateKey() // create accounts for test address1 := crypto.PubkeyToAddress(privateKey1.PublicKey) privateKey2, _ := crypto.GenerateKey() // create accounts for test @@ -356,7 +357,7 @@ func TestVoteCommissionFail(t *testing.T) { address6 := crypto.PubkeyToAddress(privateKey6.PublicKey) state := DefaultAppState() // generate default state - state.Version = "v230" + state.Version = "v300" // add address to genesis state state.Accounts = append(state.Accounts, types.Account{ @@ -716,7 +717,7 @@ func TestVoteCommissionOKUpdateVersion(t *testing.T) { address6 := crypto.PubkeyToAddress(privateKey6.PublicKey) state := DefaultAppState() // generate default state - state.Version = "v230" + state.Version = "v300" // add address to genesis state state.Accounts = append(state.Accounts, types.Account{ @@ -956,7 +957,7 @@ func TestVoteCommissionOKUpdateVersion(t *testing.T) { SendBeginBlock(app, haltBlockV210+2) // send BeginBlock { - tx := CreateTx(app, address1, transaction.TypeVoteCommission, transaction.VoteCommissionDataV1{ + tx := CreateTx(app, address1, transaction.TypeVoteCommission, transaction.VoteCommissionDataV3{ PubKey: types.Pubkey{1}, Coin: types.GetBaseCoinID(), Height: haltBlockV210 + 4, @@ -971,7 +972,7 @@ func TestVoteCommissionOKUpdateVersion(t *testing.T) { } } { - tx := CreateTx(app, address2, transaction.TypeVoteCommission, transaction.VoteCommissionDataV1{ + tx := CreateTx(app, address2, transaction.TypeVoteCommission, transaction.VoteCommissionDataV3{ PubKey: types.Pubkey{2}, Coin: types.GetBaseCoinID(), Height: haltBlockV210 + 4, From eba7cacf8ddbaebadfcd68e9bc2827112703ac06 Mon Sep 17 00:00:00 2001 From: klim0v Date: Tue, 31 May 2022 19:44:20 +0300 Subject: [PATCH 20/48] wip: tests --- coreV2/minter/blockchain.go | 16 +- tests/votes_test.go | 8 +- tests2/helper_test.go | 345 ++++++++++++++++++++++++++++++++++++ tests2/send_test.go | 44 +++++ tests2/update_test.go | 99 +++++++++++ 5 files changed, 506 insertions(+), 6 deletions(-) create mode 100644 tests2/helper_test.go create mode 100644 tests2/send_test.go create mode 100644 tests2/update_test.go diff --git a/coreV2/minter/blockchain.go b/coreV2/minter/blockchain.go index 581d602b9..9de042b80 100644 --- a/coreV2/minter/blockchain.go +++ b/coreV2/minter/blockchain.go @@ -100,6 +100,14 @@ type Blockchain struct { wgSnapshot sync.WaitGroup } +func (blockchain *Blockchain) UpdateStakesAndPayRewardsPeriod() uint64 { + return blockchain.updateStakesAndPayRewardsPeriod +} + +func (blockchain *Blockchain) ExpiredOrdersPeriod() uint64 { + return blockchain.expiredOrdersPeriod +} + func (blockchain *Blockchain) GetCurrentRewards() *big.Int { return blockchain.rewards } @@ -201,7 +209,11 @@ func (blockchain *Blockchain) initState() { } blockchain.appDB.SetState(stateDeliver.Tree()) - atomic.StoreUint64(&blockchain.height, currentHeight) + height := currentHeight + if height == 0 { + height = initialHeight + } + atomic.StoreUint64(&blockchain.height, height) blockchain.stateDeliver = stateDeliver blockchain.stateCheck = state.NewCheckState(stateDeliver) @@ -328,7 +340,7 @@ func (blockchain *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTy versionName := blockchain.appDB.GetVersionName(height) if _, ok := blockchain.knownUpdates[versionName]; !ok { - log.Printf("Update your node binary to the latest version: %s", versionName) + log.Printf("Update your node binary to the latest version: %s, height: %d", versionName, height) blockchain.stop() return abciTypes.ResponseBeginBlock{} } diff --git a/tests/votes_test.go b/tests/votes_test.go index dabd5ab92..5f8147bdf 100644 --- a/tests/votes_test.go +++ b/tests/votes_test.go @@ -987,7 +987,7 @@ func TestVoteCommissionOKUpdateVersion(t *testing.T) { } } { - tx := CreateTx(app, address3, transaction.TypeVoteCommission, transaction.VoteCommissionDataV1{ + tx := CreateTx(app, address3, transaction.TypeVoteCommission, transaction.VoteCommissionDataV3{ PubKey: types.Pubkey{3}, Coin: types.GetBaseCoinID(), Height: haltBlockV210 + 4, @@ -1007,7 +1007,7 @@ func TestVoteCommissionOKUpdateVersion(t *testing.T) { SendBeginBlock(app, haltBlockV210+3) // send BeginBlock { - tx := CreateTx(app, address5, transaction.TypeVoteCommission, transaction.VoteCommissionDataV1{ + tx := CreateTx(app, address5, transaction.TypeVoteCommission, transaction.VoteCommissionDataV3{ PubKey: types.Pubkey{5}, Coin: types.GetBaseCoinID(), Height: haltBlockV210 + 4, @@ -1022,7 +1022,7 @@ func TestVoteCommissionOKUpdateVersion(t *testing.T) { } } { - tx := CreateTx(app, address6, transaction.TypeVoteCommission, transaction.VoteCommissionDataV1{ + tx := CreateTx(app, address6, transaction.TypeVoteCommission, transaction.VoteCommissionDataV3{ PubKey: types.Pubkey{6}, Coin: types.GetBaseCoinID(), Height: haltBlockV210 + 4, @@ -1038,7 +1038,7 @@ func TestVoteCommissionOKUpdateVersion(t *testing.T) { } { // Diff - tx := CreateTx(app, address4, transaction.TypeVoteCommission, transaction.VoteCommissionDataV1{ + tx := CreateTx(app, address4, transaction.TypeVoteCommission, transaction.VoteCommissionDataV3{ PubKey: types.Pubkey{4}, Coin: types.GetBaseCoinID(), Height: haltBlockV210 + 4, diff --git a/tests2/helper_test.go b/tests2/helper_test.go new file mode 100644 index 000000000..539d0f10e --- /dev/null +++ b/tests2/helper_test.go @@ -0,0 +1,345 @@ +package tests + +import ( + "crypto/ecdsa" + "fmt" + "github.com/MinterTeam/minter-go-node/coreV2/state/coins" + "time" + + "github.com/MinterTeam/minter-go-node/cmd/utils" + "github.com/MinterTeam/minter-go-node/config" + "github.com/MinterTeam/minter-go-node/coreV2/minter" + "github.com/MinterTeam/minter-go-node/coreV2/transaction" + "github.com/MinterTeam/minter-go-node/coreV2/types" + "github.com/MinterTeam/minter-go-node/crypto" + "github.com/MinterTeam/minter-go-node/rlp" + "github.com/tendermint/go-amino" + tmTypes "github.com/tendermint/tendermint/abci/types" + tmTypes1 "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/tendermint/tendermint/proto/tendermint/version" +) + +func init() { + types.CurrentChainID = types.ChainTestnet +} + +func CreateAppDefault(state types.AppState) *minter.Blockchain { + const ( + updateStakePeriod = 12 + expiredOrdersPeriod = 24 + ) + return CreateApp(state, updateStakePeriod, expiredOrdersPeriod, 999) +} + +func CreateApp(state types.AppState, updateStakePeriod, expiredOrdersPeriod uint64, initialHeightOmitempty int64) *minter.Blockchain { + jsonState, err := amino.MarshalJSON(state) + if err != nil { + panic(err) + } + + storage := utils.NewStorage("", "") + cfg := config.GetConfig(storage.GetMinterHome()) + cfg.DBBackend = "memdb" + + app := minter.NewMinterBlockchain(storage, cfg, nil, updateStakePeriod, expiredOrdersPeriod, nil) + var updates []tmTypes.ValidatorUpdate + for _, validator := range state.Validators { + updates = append(updates, tmTypes.Ed25519ValidatorUpdate(validator.PubKey.Bytes(), 1)) + } + app.InitChain(tmTypes.RequestInitChain{ + Time: time.Unix(0, 0), + ChainId: "test1", + Validators: updates, + InitialHeight: initialHeightOmitempty, + AppStateBytes: jsonState, + }) + + return app +} + +type Helper struct { + app *minter.Blockchain + lastBlockTime time.Time +} + +func NewHelper(state types.AppState) *Helper { + return &Helper{lastBlockTime: time.Unix(0, 0), app: CreateAppDefault(state)} +} + +func (h *Helper) NextBlock(txs ...transaction.Transaction) (height uint64, results []tmTypes.ResponseDeliverTx) { + h.lastBlockTime = h.lastBlockTime.Add(time.Second) + SendBeginBlock(h.app, h.lastBlockTime) + for _, tx := range txs { + b, err := rlp.EncodeToBytes(tx) + if err != nil { + panic(err) + } + results = append(results, SendTx(h.app, b)) + } + SendEndBlock(h.app) + return SendCommit(h.app), results +} + +func SendCommit(app *minter.Blockchain) (height uint64) { + app.Commit() + return app.Height() +} + +func SendBeginBlock(app *minter.Blockchain, t time.Time) tmTypes.ResponseBeginBlock { + var voteInfos []tmTypes.VoteInfo + validators := app.CurrentState().Validators().GetValidators() + for _, validator := range validators { + address := validator.GetAddress() + voteInfos = append(voteInfos, tmTypes.VoteInfo{ + Validator: tmTypes.Validator{ + Address: address[:], + Power: int64(100 / len(validators)), + }, + SignedLastBlock: true, + }) + } + + return app.BeginBlock(tmTypes.RequestBeginBlock{ + Hash: nil, + Header: tmTypes1.Header{ + Version: version.Consensus{}, + ChainID: "test1", + Height: int64(app.Height() + 1), + Time: t, + LastBlockId: tmTypes1.BlockID{}, + LastCommitHash: nil, + DataHash: nil, + ValidatorsHash: nil, + NextValidatorsHash: nil, + ConsensusHash: nil, + AppHash: nil, + LastResultsHash: nil, + EvidenceHash: nil, + ProposerAddress: nil, + }, + LastCommitInfo: tmTypes.LastCommitInfo{ + Round: 0, + Votes: voteInfos, + }, + ByzantineValidators: nil, + }) +} + +func SendEndBlock(app *minter.Blockchain) tmTypes.ResponseEndBlock { + return app.EndBlock(tmTypes.RequestEndBlock{ + Height: int64(app.Height() + 1), + }) +} + +// CreateTx composes and returns Tx with given params. +// Nonce, chain id, gas price, gas coin and signature type fields are auto-filled. +func (h *Helper) CreateTx(pk *ecdsa.PrivateKey, data transaction.Data, gas types.CoinID, gasPrice ...uint32) transaction.Transaction { + address := crypto.PubkeyToAddress(pk.PublicKey) + + nonce := h.app.CurrentState().Accounts().GetNonce(address) + 1 + bData, err := rlp.EncodeToBytes(data) + if err != nil { + panic(err) + } + + var mulGas uint32 = 1 + if len(gasPrice) != 0 { + mulGas = gasPrice[0] + } + + tx := transaction.Transaction{ + Nonce: nonce, + ChainID: types.CurrentChainID, + GasPrice: mulGas, + GasCoin: gas, + Type: data.TxType(), + Data: bData, + SignatureType: transaction.SigTypeSingle, + } + + err = tx.Sign(pk) + if err != nil { + panic(err) + } + + return tx +} + +// SendTx sends DeliverTx message to given Blockchain instance +func SendTx(app *minter.Blockchain, bytes []byte) tmTypes.ResponseDeliverTx { + return app.DeliverTx(tmTypes.RequestDeliverTx{ + Tx: bytes, + }) +} + +type User struct { + address types.Address + privateKey *ecdsa.PrivateKey +} + +// CreateAddress returns random address and corresponding private key +func CreateAddress() *User { + pk, _ := crypto.GenerateKey() + + return &User{crypto.PubkeyToAddress(pk.PublicKey), pk} +} + +// DefaultAppState returns new AppState with some predefined values +func DefaultAppState(addresses ...types.Address) types.AppState { + var accounts = make([]types.Account, 0, len(addresses)) + var validators = make([]types.Validator, 0, len(addresses)) + var candidates = make([]types.Candidate, 0, len(addresses)) + + for i, addr := range addresses { + accounts = append(accounts, types.Account{ + Address: addr, + Balance: []types.Balance{{ + Coin: 0, + Value: "1000000000000000000000000000000000", + }, { + Coin: types.USDTID, + Value: "1000000000000000000000000000000", + }}, + Nonce: 0, + MultisigData: nil, + LockStakeUntilBlock: 0, + }) + validators = append(validators, types.Validator{ + TotalBipStake: "2000000000000000000000000000000000", + PubKey: types.Pubkey{byte(i)}, + AccumReward: "100", + AbsentTimes: types.NewBitArray(24), + }) + candidates = append(candidates, types.Candidate{ + ID: uint64(i + 1), + RewardAddress: types.Address{byte(0), byte(i)}, + OwnerAddress: addr, + ControlAddress: addr, + TotalBipStake: "2000000000000000000000000000000000", + PubKey: types.Pubkey{byte(i)}, + Commission: 10, + Stakes: []types.Stake{{ + Owner: addr, + Coin: 0, + Value: "1000000000000000000000000000000000", + BipValue: "1000000000000000000000000000000000", + }, { + Owner: types.Address{byte(i)}, + Coin: 0, + Value: "1000000000000000000000000000000000", + BipValue: "1000000000000000000000000000000000", + }}, + Updates: []types.Stake{{ + Owner: addr, + Coin: 0, + Value: "500000000000000000000000000000000", + BipValue: "500000000000000000000000000000000", + }}, + Status: 2, + JailedUntil: 0, + LastEditCommissionHeight: 0, + }) + } + + return types.AppState{ + Note: "test1", + Validators: validators, + Candidates: candidates, + BlockListCandidates: nil, + DeletedCandidates: nil, + Waitlist: nil, + Pools: []types.Pool{{ + Coin0: 0, + Coin1: types.USDTID, + Reserve0: "1000000000000000000000000000000000", + Reserve1: "1000000000000000000000000000000", + ID: 1, + Orders: nil, + }}, + NextOrderID: 0, + Accounts: accounts, + Coins: []types.Coin{ + { + ID: types.USDTID, + Name: "USDT Eth", + Symbol: types.StrToCoinSymbol("USDTE"), + Volume: fmt.Sprintf("%d000000000000000000000000000000", len(accounts)+1), + Crr: 0, + Reserve: "0", + MaxSupply: coins.MaxCoinSupply().String(), + Version: 0, + OwnerAddress: nil, + Mintable: true, + Burnable: true, + }, + }, + FrozenFunds: nil, + HaltBlocks: nil, + Commission: types.Commission{ + Coin: types.USDTID, + PayloadByte: "2000000000000", + Send: "10000000000000", + BuyBancor: "100000000000000", + SellBancor: "100000000000000", + SellAllBancor: "100000000000000", + BuyPoolBase: "100000000000000", + BuyPoolDelta: "50000000000000", + SellPoolBase: "100000000000000", + SellPoolDelta: "50000000000000", + SellAllPoolBase: "100000000000000", + SellAllPoolDelta: "50000000000000", + CreateTicker3: "1000000000000000000000", + CreateTicker4: "100000000000000000000", + CreateTicker5: "10000000000000000000", + CreateTicker6: "1000000000000000000", + CreateTicker7_10: "100000000000000000", + CreateCoin: "200000000000000", + CreateToken: "200000000000000", + RecreateCoin: "10000000000000000000", + RecreateToken: "10000000000000000000", + DeclareCandidacy: "10000000000000000", + Delegate: "200000000000000", + Unbond: "200000000000000", + RedeemCheck: "30000000000000", + SetCandidateOn: "100000000000000", + SetCandidateOff: "100000000000000", + CreateMultisig: "100000000000000", + MultisendBase: "10000000000000", + MultisendDelta: "5000000000000", + EditCandidate: "10000000000000000", + SetHaltBlock: "1000000000000000", + EditTickerOwner: "10000000000000000000", + EditMultisig: "1000000000000000", + EditCandidatePublicKey: "100000000000000000000", + CreateSwapPool: "1000000000000000", + AddLiquidity: "100000000000000", + RemoveLiquidity: "100000000000000", + EditCandidateCommission: "10000000000000000", + MintToken: "100000000000000", + BurnToken: "100000000000000", + VoteCommission: "1000000000000000", + VoteUpdate: "1000000000000000", + FailedTx: "5000000000000", + AddLimitOrder: "300000000000000", + RemoveLimitOrder: "100000000000000", + MoveStake: "500000000000000", + LockStake: "100000000000000", + Lock: "200000000000000", + }, + CommissionVotes: nil, + UpdateVotes: nil, + UsedChecks: nil, + MaxGas: 0, + TotalSlashed: "0", + Emission: "9999", + PrevReward: types.RewardPrice{ + Time: 0, + AmountBIP: "350", + AmountUSDT: "1", + Off: false, + Reward: "74000000000000000000", + }, + Version: "v300", + Versions: nil, + } +} diff --git a/tests2/send_test.go b/tests2/send_test.go new file mode 100644 index 000000000..ae07b2d50 --- /dev/null +++ b/tests2/send_test.go @@ -0,0 +1,44 @@ +package tests + +import ( + "github.com/MinterTeam/minter-go-node/coreV2/code" + "github.com/MinterTeam/minter-go-node/coreV2/transaction" + "github.com/MinterTeam/minter-go-node/coreV2/types" + "math/big" + "testing" +) + +func TestSend(t *testing.T) { + sender := CreateAddress() // create account for test + + helper := NewHelper(DefaultAppState(sender.address)) + + initialBIPBalance := helper.app.CurrentState().Accounts().GetBalance(sender.address, 0) + initialUSDTBalance := helper.app.CurrentState().Accounts().GetBalance(sender.address, types.USDTID) + + recipient := CreateAddress() // generate recipient + value := big.NewInt(1) + tx := helper.CreateTx(sender.privateKey, transaction.SendData{ + Coin: types.GetBaseCoinID(), + To: recipient.address, + Value: value, + }, types.USDTID) + + _, results := helper.NextBlock(tx) + + for _, resp := range results { + if resp.Code != code.OK { + t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) + } + } + + if big.NewInt(0).Sub(initialUSDTBalance, helper.app.CurrentState().Commission().GetCommissions().Send).String() != helper.app.CurrentState().Accounts().GetBalance(sender.address, types.USDTID).String() { + t.Fatalf("error sender usd balance") + } + if big.NewInt(0).Sub(initialBIPBalance, value).String() != helper.app.CurrentState().Accounts().GetBalance(sender.address, 0).String() { + t.Fatalf("error sender bip balance") + } + if value.String() != helper.app.CurrentState().Accounts().GetBalance(recipient.address, 0).String() { + t.Fatalf("error recipient bip balance") + } +} diff --git a/tests2/update_test.go b/tests2/update_test.go new file mode 100644 index 000000000..48da11f7e --- /dev/null +++ b/tests2/update_test.go @@ -0,0 +1,99 @@ +package tests + +import ( + "fmt" + "github.com/MinterTeam/minter-go-node/coreV2/code" + "github.com/MinterTeam/minter-go-node/coreV2/events" + "github.com/MinterTeam/minter-go-node/coreV2/minter" + "github.com/MinterTeam/minter-go-node/coreV2/transaction" + "github.com/MinterTeam/minter-go-node/coreV2/types" + "testing" + "time" +) + +func TestUpdate(t *testing.T) { + for _, valCount := range []int{1, 4, 20, 50, 70} { + t.Run(fmt.Sprintf("%dvals", valCount), func(t *testing.T) { + testUpdate(t, valCount, minter.V310, minter.V320, minter.V330) + }) + } +} + +func testUpdate(t *testing.T, valCount int, versions ...string) { + var voters []*User + var addresses []types.Address + for i := 0; i < valCount; i++ { + voter := CreateAddress() + voters = append(voters, voter) + addresses = append(addresses, voter.address) + } + + helper := NewHelper(DefaultAppState(addresses...)) + + for _, version := range versions { + t.Run(version, func(t *testing.T) { + var txs []transaction.Transaction + height := helper.app.Height() + 5 + for i, voter := range voters { + txs = append(txs, helper.CreateTx(voter.privateKey, transaction.VoteUpdateDataV230{ + Version: version, + PubKey: types.Pubkey{byte(i)}, + Height: height, + }, types.USDTID)) + } + + _, results := helper.NextBlock(txs...) + + for _, resp := range results { + if resp.Code != code.OK { + t.Errorf("Response code is not OK: %d, %s", resp.Code, resp.Log) + } + } + + updatedHeight := height + for h := uint64(0); h <= updatedHeight+1; h, _ = helper.NextBlock() { + } + + var updated bool + for _, event := range helper.app.GetEventsDB().LoadEvents(uint32(updatedHeight)) { + if event.Type() == events.TypeUpdateNetworkEvent { + updateNetworkEvent, ok := event.(*events.UpdateNetworkEvent) + if !ok { + t.Error("incorrect event type") + continue + } + if updateNetworkEvent.Version != version { + t.Error("incorrect version", updateNetworkEvent.Version) + continue + } + updated = true + } + } + + if !updated { + t.Error("network is not updated") + } + + testBlock50(t, helper) + }) + } +} + +func testBlock50(t *testing.T, helper *Helper) { + initial := helper.app.Height() + + c := make(chan struct{}) + go func() { + for h := uint64(0); h <= initial+50; h, _ = helper.NextBlock() { + } + c <- struct{}{} + }() + + select { + case <-c: + return + case <-time.After(10 * time.Second): + t.Fatal("deadline") + return + } +} From d1ad22d69a66e2961a2c3356d628047a990a8830 Mon Sep 17 00:00:00 2001 From: klim0v Date: Tue, 31 May 2022 21:09:53 +0300 Subject: [PATCH 21/48] wip: tests --- coreV2/minter/blockchain.go | 4 + coreV2/minter/minter_test.go | 2 +- tests/failed_test.go | 1430 ----------------- {tests2 => tests}/helper_test.go | 13 + tests/send_test.go | 163 +- {tests2 => tests}/update_test.go | 0 tests2/send_test.go | 44 - {tests => tests_old}/byz_test.go | 2 +- {tests => tests_old}/candidates_test.go | 2 +- {tests => tests_old}/emission_test.go | 2 +- .../example/counter/counter.go | 0 tests_old/failed_test.go | 1422 ++++++++++++++++ {tests => tests_old}/helpers_test.go | 2 +- {tests => tests_old}/lock_test.go | 4 +- {tests => tests_old}/move_test.go | 2 +- {tests => tests_old}/order_test.go | 18 +- {tests => tests_old}/reward3_test.go | 3 +- tests_old/send_test.go | 68 + {tests => tests_old}/swap3_test.go | 2 +- {tests => tests_old}/votes_test.go | 2 +- 20 files changed, 1643 insertions(+), 1542 deletions(-) delete mode 100644 tests/failed_test.go rename {tests2 => tests}/helper_test.go (98%) rename {tests2 => tests}/update_test.go (100%) delete mode 100644 tests2/send_test.go rename {tests => tests_old}/byz_test.go (99%) rename {tests => tests_old}/candidates_test.go (99%) rename {tests => tests_old}/emission_test.go (99%) rename {tests => tests_old}/example/counter/counter.go (100%) create mode 100644 tests_old/failed_test.go rename {tests => tests_old}/helpers_test.go (99%) rename {tests => tests_old}/lock_test.go (98%) rename {tests => tests_old}/move_test.go (98%) rename {tests => tests_old}/order_test.go (99%) rename {tests => tests_old}/reward3_test.go (99%) create mode 100644 tests_old/send_test.go rename {tests => tests_old}/swap3_test.go (99%) rename {tests => tests_old}/votes_test.go (99%) diff --git a/coreV2/minter/blockchain.go b/coreV2/minter/blockchain.go index 9de042b80..7917d576e 100644 --- a/coreV2/minter/blockchain.go +++ b/coreV2/minter/blockchain.go @@ -100,6 +100,10 @@ type Blockchain struct { wgSnapshot sync.WaitGroup } +func (blockchain *Blockchain) Executor() transaction.ExecutorTx { + return blockchain.executor +} + func (blockchain *Blockchain) UpdateStakesAndPayRewardsPeriod() uint64 { return blockchain.updateStakesAndPayRewardsPeriod } diff --git a/coreV2/minter/minter_test.go b/coreV2/minter/minter_test.go index 2f78e0326..ab3f66773 100644 --- a/coreV2/minter/minter_test.go +++ b/coreV2/minter/minter_test.go @@ -417,7 +417,7 @@ func TestBlockchain_SetStatisticData(t *testing.T) { } func TestBlockchain_IsApplicationHalted(t *testing.T) { - t.Skip("todo") + //t.Skip("todo") blockchain, tmCli, pv, cancel := initTestNode(t, 0) defer cancel() // unexpected call to os.Exit(0) during test data := transaction.SetHaltBlockData{ diff --git a/tests/failed_test.go b/tests/failed_test.go deleted file mode 100644 index f69701ece..000000000 --- a/tests/failed_test.go +++ /dev/null @@ -1,1430 +0,0 @@ -package tests - -import ( - "math/big" - "testing" - - "github.com/MinterTeam/minter-go-node/coreV2/transaction" - "github.com/MinterTeam/minter-go-node/coreV2/types" - "github.com/MinterTeam/minter-go-node/helpers" -) - -func TestFailedTxPayCommission(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "100", - Crr: 0, - Reserve: "0", - MaxSupply: "100", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "50", - ID: 1, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "1", - }, - { - Coin: 1, - Value: "50", - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(1)) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 107 { - t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(big.NewInt(1)) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - // check commission balance - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "49" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "49", balance) - } - } - - // check pool reserves - { - reward := app.GetCurrentRewards() - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() - if reward.Sign() != 1 || r1.String() != "51" || big.NewInt(0).Add(reward, r0).Cmp(reserve0) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "51", r0, r1, reward) - } - } - -} - -func TestFailedTxPayCommission_customPriceCoin(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(4e18).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "1", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(1)) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 107 { - t.Fatalf("Response code is not error: %s, %d", response.Log, response.Code) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(big.NewInt(1)) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - // check commission balance - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "6000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "49", balance) - } - } - - // check pool reserves - { - reward := app.GetCurrentRewards() - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() - if reward.Sign() != 1 || r1.String() != "6345678901234567890" || big.NewInt(0).Add(reward, r0).Cmp(reserve0) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "51", r0, r1, reward) - } - } - -} - -func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin_lessAvailable(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(4e18).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "10000000000000000000", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: 2, - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(0)) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 102 { - t.Fatalf("Response code is not error: %s, %d", response.Log, response.Code) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(big.NewInt(0)) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - // check commission balance - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "10000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) - } - } - - // check pool reserves - { - reward := app.GetCurrentRewards() - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() - if reward.String() != "10000000000000000000" || r1.String() != "2345678901234567890" { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "5000000000000000000000000000000000000", r0, r1, reward) - } - } - -} - -func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin_lessAvailable_withGasPrice(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(4e18).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "10000000000000000000", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: 2, - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(0), 50) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 102 { - t.Fatalf("Response code is not error: %s, %d", response.Log, response.Code) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(big.NewInt(0)) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - // check commission balance - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "10000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) - } - } - - // check pool reserves - { - reward := app.GetCurrentRewards() - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() - if reward.String() != "10000000000000000000" || r1.String() != "2345678901234567890" { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "5000000000000000000000000000000000000", r0, r1, reward) - } - } - -} - -func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin_withGasPrice(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(4e18).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "10000000000000000000000000000000000000", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: 2, - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(0), 50) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 102 { - t.Fatalf("Response code is not error: %s, %d", response.Log, response.Code) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(helpers.StringToBigInt("5058076976788935588754051349077150287")) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - // check commission balance - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "10000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) - } - } - - // check pool reserves - { - reward := app.GetCurrentRewards() - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() - if reward.String() != "4941923023211064411245948650922849713" || r1.String() != "2345678901234567890" { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "5000000000000000000000000000000000000", r0, r1, reward) - } - } -} - -func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(4e18).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "10000000000000000000000000000000000000", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: 2, - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(0), 1) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 102 { - t.Fatalf("Response code is not error: %s, %d", response.Log, response.Code) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(helpers.StringToBigInt("6850582001541316700832722827411023323")) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - // check commission balance - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "10000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) - } - } - - // check pool reserves - { - reward := app.GetCurrentRewards() - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() - if reward.String() != "3149417998458683299167277172588976677" || r1.String() != "2345678901234567890" { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "5000000000000000000000000000000000000", r0, r1, reward) - } - } -} - -func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionToken(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }, types.Coin{ - ID: 2, - Name: "bbb", - Symbol: types.StrToCoinBaseSymbol("BBB"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(4e18).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }, types.Pool{ - Coin0: 0, - Coin1: 2, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 2, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "1", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - { - Coin: 2, - Value: "10000000000000000000", - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(2)) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 107 { - t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(big.NewInt(1)) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "10000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) - } - } - - // check commission balance - { - balance := app.CurrentState().Accounts().GetBalance(address, 2) - if balance.String() != "6000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "6000000000000000000", balance) - } - } - - // check pool reserves - { - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() - if r0.String() != "5000000000000000000000000000000000000" || r1.String() != "2345678901234567890" { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s", "5000000000000000000000000000000000000", r0, r1) - } - } - // check pool reserves - { - reward := app.GetCurrentRewards() - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 2).Reserves() - if reward.Sign() != 1 || r1.String() != "6345678901234567890" || big.NewInt(0).Add(reward, r0).Cmp(reserve0) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "51", r0, r1, reward) - } - } - -} - -func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionToken_withGasPrice(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }, types.Coin{ - ID: 2, - Name: "bbb", - Symbol: types.StrToCoinBaseSymbol("BBB"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(4e18).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }, types.Pool{ - Coin0: 0, - Coin1: 2, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 2, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "1", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - { - Coin: 2, - Value: "10000000000000000000", - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(2), 2) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 107 { - t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(big.NewInt(1)) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "10000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) - } - } - - // check commission balance - { - balance := app.CurrentState().Accounts().GetBalance(address, 2) - if balance.String() != "2000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "2000000000000000000", balance) - } - } - - // check pool reserves - { - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() - if r0.String() != "5000000000000000000000000000000000000" || r1.String() != "2345678901234567890" { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s", "5000000000000000000000000000000000000", r0, r1) - } - } - - // check pool reserves - { - reward := app.GetCurrentRewards() - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 2).Reserves() - if reward.Sign() != 1 || r1.String() != "10345678901234567890" || big.NewInt(0).Add(reward, r0).Cmp(reserve0) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "1135407462159458011337752529693750189", r0, r1, reward) - } - } -} - -func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionToken_withGasPrice_lessAvailable(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }, types.Coin{ - ID: 2, - Name: "bbb", - Symbol: types.StrToCoinBaseSymbol("BBB"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(4e18).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }, types.Pool{ - Coin0: 0, - Coin1: 2, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 2, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "1", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - { - Coin: 2, - Value: "10000000000000000000", - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(2), 50) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 107 { - t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(big.NewInt(1)) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "10000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) - } - } - - // check commission balance - { - balance := app.CurrentState().Accounts().GetBalance(address, 2) - if balance.String() != "0" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "0", balance) - } - } - - // check pool reserves - { - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() - if r0.String() != "5000000000000000000000000000000000000" || r1.String() != "2345678901234567890" { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s", "5000000000000000000000000000000000000", r0, r1) - } - } - - // check pool reserves - { - reward := app.GetCurrentRewards() - r0, r1 := app.CurrentState().Swap().GetSwapper(0, 2).Reserves() - if reward.Sign() != 1 || r1.String() != "12345678901234567890" || big.NewInt(0).Add(reward, r0).Cmp(reserve0) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "951541460730256157863947745387590710", r0, r1, reward) - } - } -} - -func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCoin(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }, types.Coin{ - ID: 2, - Name: "bbb", - Symbol: types.StrToCoinBaseSymbol("BBB"), - Volume: "695664472679", - Crr: 50, - Reserve: "3149417998458693299167277172588976677", - MaxSupply: "695664472679", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(4e18).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "1", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - { - Coin: 2, - Value: "695664472679", - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(2)) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 107 { - t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(big.NewInt(1)) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "10000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) - } - } - - // check commission balance - { - coin := app.CurrentState().Coins().GetCoin(2) - balance := app.CurrentState().Accounts().GetBalance(address, 2) - if balance.String() != "39200" && coin.Volume().String() != "39200" { - t.Fatalf("volume or balance is not correct. Expected %s, got %s and coin volume %s", "49", balance, coin.Volume()) - } - - if coin.Reserve().Cmp(helpers.StringToBigInt("10000000000000000000000")) == -1 { - t.Fatalf("reserve is not correct. Got %s", coin.Reserve()) - } - } - -} - -func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCoin_withGasPrice(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }, types.Coin{ - ID: 2, - Name: "bbb", - Symbol: types.StrToCoinBaseSymbol("BBB"), - Volume: "695664472679", - Crr: 50, - Reserve: "4941923023211074411245948650922849713", - MaxSupply: "695664472679", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(4e18).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "1", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - { - Coin: 2, - Value: "695664472679", - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(2), 50) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 107 { - t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(big.NewInt(1)) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "10000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) - } - } - - // check commission balance - { - coin := app.CurrentState().Coins().GetCoin(2) - balance := app.CurrentState().Accounts().GetBalance(address, 2) - if balance.String() != "31294" && coin.Volume().String() != "31294" { - t.Fatalf("volume or balance is not correct. Expected %s, got %s and coin volume %s", "31294", balance, coin.Volume()) - } - - if coin.Reserve().Cmp(helpers.StringToBigInt("10000000000000000000000")) == -1 { - t.Fatalf("reserve is not correct. Got %s", coin.Reserve()) - } - } - -} - -func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCoin_withGasPrice_lessAvailable(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }, types.Coin{ - ID: 2, - Name: "bbb", - Symbol: types.StrToCoinBaseSymbol("BBB"), - Volume: "695664472679", - Crr: 50, - Reserve: "4941923023211074411245948650922849713", - MaxSupply: "695664472679", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(4e18).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "1", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - { - Coin: 2, - Value: "95664472679", - }, - }, - Nonce: 0, - MultisigData: nil, - }, - types.Account{ - Address: types.Address{}, - Balance: []types.Balance{ - { - Coin: 2, - Value: "600000000000", - }, - }, - }, - ) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(2), 50) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 107 { - t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(big.NewInt(1)) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "10000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) - } - } - - // check commission balance - { - coin := app.CurrentState().Coins().GetCoin(2) - balance := app.CurrentState().Accounts().GetBalance(address, 2) - if balance.String() != "0" && coin.Volume().String() != "600000000000" { - t.Fatalf("volume or balance is not correct. Expected %s, got %s and coin volume %s", "0", balance, coin.Volume()) - } - - if coin.Reserve().Cmp(helpers.StringToBigInt("10000000000000000000000")) == -1 { - t.Fatalf("reserve is not correct. Got %s", coin.Reserve()) - } - } - -} - -func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCoin_withGasPrice_lessReserve(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - state.Version = "v300" - - state.Coins = append(state.Coins, types.Coin{ - ID: 1, - Name: "aaa", - Symbol: types.StrToCoinBaseSymbol("AAA"), - Volume: "12345678901234567890", - Crr: 0, - Reserve: "0", - MaxSupply: "12345678901234567890", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }, types.Coin{ - ID: 2, - Name: "bbb", - Symbol: types.StrToCoinBaseSymbol("BBB"), - Volume: "695664472679", - Crr: 50, - Reserve: "4941923023211074411245948650922849710", - MaxSupply: "695664472679", - Version: 0, - OwnerAddress: nil, - Mintable: false, - Burnable: false, - }) - state.Commission.Coin = 1 - state.Commission.FailedTx = big.NewInt(1e15).String() - - reserve0 := helpers.BipToPip(big.NewInt(5e18)) - state.Pools = append(state.Pools, types.Pool{ - Coin0: 0, - Coin1: 1, - Reserve0: reserve0.String(), - Reserve1: "2345678901234567890", - ID: 1, - }) - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: "1", - }, - { - Coin: 1, - Value: "10000000000000000000", - }, - { - Coin: 2, - Value: "95664472679", - }, - }, - Nonce: 0, - MultisigData: nil, - }, - types.Account{ - Address: types.Address{}, - Balance: []types.Balance{ - { - Coin: 2, - Value: "600000000000", - }, - }, - }, - ) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient, - Value: big.NewInt(100), - }, types.CoinID(2), 50) - - response := SendTx(app, SignTx(pk, tx)) // compose and send tx - - // check that result is error - if response.Code != 107 { - t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) - } - - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit - - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.Cmp(big.NewInt(1)) != 0 { - t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) - } - } - - { - balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != "10000000000000000000" { - t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) - } - } - - // check commission balance - { - coin := app.CurrentState().Coins().GetCoin(2) - balance := app.CurrentState().Accounts().GetBalance(address, 2) - if balance.String() != "88294932483" && coin.Volume().String() != "688294932483" { - t.Fatalf("volume or balance is not correct. Expected %s, got %s and coin volume %s", "88294932483", balance, coin.Volume()) - } - - if coin.Reserve().Cmp(helpers.StringToBigInt("10000000000000000000000")) == -1 { - t.Fatalf("reserve is not correct. Got %s", coin.Reserve()) - } - } - -} diff --git a/tests2/helper_test.go b/tests/helper_test.go similarity index 98% rename from tests2/helper_test.go rename to tests/helper_test.go index 539d0f10e..15707fa9d 100644 --- a/tests2/helper_test.go +++ b/tests/helper_test.go @@ -162,6 +162,19 @@ func (h *Helper) CreateTx(pk *ecdsa.PrivateKey, data transaction.Data, gas types panic(err) } + d, ok := transaction.GetData(data.TxType()) + if !ok { + panic(fmt.Sprintf("tx type %x is not registered", tx.Type)) + } + + err = rlp.DecodeBytes(tx.Data, d) + + if err != nil { + panic(err) + } + + tx.SetDecodedData(d) + return tx } diff --git a/tests/send_test.go b/tests/send_test.go index 602912791..e216aa5ef 100644 --- a/tests/send_test.go +++ b/tests/send_test.go @@ -1,68 +1,135 @@ package tests import ( - "math/big" - "testing" - + "fmt" "github.com/MinterTeam/minter-go-node/coreV2/code" "github.com/MinterTeam/minter-go-node/coreV2/transaction" "github.com/MinterTeam/minter-go-node/coreV2/types" - "github.com/MinterTeam/minter-go-node/helpers" + "math" + "math/big" + "testing" ) -func TestSend(t *testing.T) { - address, pk := CreateAddress() // create account for test - - state := DefaultAppState() // generate default state - - // add address to genesis state - state.Accounts = append(state.Accounts, types.Account{ - Address: address, - Balance: []types.Balance{ - { - Coin: uint64(types.GetBaseCoinID()), - Value: helpers.StringToBigInt("100000000000000000000").String(), - }, - }, - Nonce: 0, - MultisigData: nil, - }) - - app := CreateApp(state) // create application - SendBeginBlock(app, 1) // send BeginBlock - - recipient, _ := CreateAddress() // generate recipient - value := big.NewInt(1) +type diffBalance struct { + Coin types.CoinID + Value *big.Int +} - tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient, - Value: value, - }, 0) +func TestEditBalance(t *testing.T) { + sender := CreateAddress() // create account for test + + helper := NewHelper(DefaultAppState(sender.address)) - response := SendTx(app, SignTx(pk, tx)) // compose and send tx + var transactions []func() (transaction.Transaction, []*diffBalance) - // check that result is OK - if response.Code != code.OK { - t.Fatalf("Response code is not OK: %s, %d", response.Log, response.Code) + for _, coin := range []types.CoinID{types.BasecoinID, types.USDTID} { + coin := coin + { + recipient := CreateAddress() + value := big.NewInt(1) + transactions = append(transactions, func() (transaction.Transaction, []*diffBalance) { + return helper.CreateTx(sender.privateKey, transaction.SendData{ + Coin: coin, + To: recipient.address, + Value: value, + }, types.USDTID), []*diffBalance{{ + Coin: coin, + Value: value}} + }) + } + { + value := big.NewInt(1) + transactions = append(transactions, func() (transaction.Transaction, []*diffBalance) { + return helper.CreateTx(sender.privateKey, transaction.LockData{ + DueBlock: math.MaxUint32, + Coin: coin, + Value: value, + }, types.USDTID), []*diffBalance{{ + Coin: coin, + Value: value}} + }) + } + } + + for _, txFunc := range transactions { + tx, diffs := txFunc() + t.Run(fmt.Sprintf("TxType=%s,%#v", tx.Type, tx.GetDecodedData()), func(t *testing.T) { + testBalance(t, helper, tx, diffs) + }) + } +} +func testBalance(t *testing.T, helper *Helper, tx transaction.Transaction, diffs []*diffBalance) { + sender, _ := tx.Sender() + + initialCommissionCoinBalance := helper.app.CurrentState().Accounts().GetBalance(sender, tx.CommissionCoin()) + + var initialBalances []*big.Int + for _, diff := range diffs { + initialBalances = append(initialBalances, helper.app.CurrentState().Accounts().GetBalance(sender, diff.Coin)) } - SendEndBlock(app, 1) // send EndBlock - SendCommit(app) // send Commit + _, results := helper.NextBlock(tx) - // check recipient's balance - { - balance := app.CurrentState().Accounts().GetBalance(recipient, types.GetBaseCoinID()) - if balance.Cmp(value) != 0 { - t.Fatalf("Recipient balance is not correct. Expected %s, got %s", value, balance) + for _, resp := range results { + if resp.Code != code.OK { + t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) } } - // check sender's balance - { - balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) - if balance.String() != "99989999999999999999" { - t.Fatalf("Recipient balance is not correct. Expected %s, got %s", "98999999999999999999", balance) + var checkedCommissionCoin bool + for i, diff := range diffs { + newBalance := big.NewInt(0).Sub(initialBalances[i], diff.Value) + if diff.Coin == tx.CommissionCoin() { + if tx.CommissionCoin() != types.USDTID { + panic("unimplemented test commission coin not equal USDT") + } + checkedCommissionCoin = true + newBalance.Sub(newBalance, tx.MulGasPrice(tx.Price(helper.app.CurrentState().Commission().GetCommissions()))) } + if newBalance.String() != helper.app.CurrentState().Accounts().GetBalance(sender, diff.Coin).String() { + t.Errorf("error sender CoinID-%d balance", diff.Coin) + } + } + + if !checkedCommissionCoin { + if big.NewInt(0).Sub(initialCommissionCoinBalance, tx.Price(helper.app.CurrentState().Commission().GetCommissions())).String() != helper.app.CurrentState().Accounts().GetBalance(sender, tx.CommissionCoin()).String() { + t.Error("error sender usd balance") + } + } + +} + +func TestSend(t *testing.T) { + sender := CreateAddress() // create account for test + + helper := NewHelper(DefaultAppState(sender.address)) + + initialBIPBalance := helper.app.CurrentState().Accounts().GetBalance(sender.address, 0) + initialUSDTBalance := helper.app.CurrentState().Accounts().GetBalance(sender.address, types.USDTID) + + recipient := CreateAddress() // generate recipient + value := big.NewInt(1) + tx := helper.CreateTx(sender.privateKey, transaction.SendData{ + Coin: types.GetBaseCoinID(), + To: recipient.address, + Value: value, + }, types.USDTID) + + _, results := helper.NextBlock(tx) + + for _, resp := range results { + if resp.Code != code.OK { + t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) + } + } + + if big.NewInt(0).Sub(initialUSDTBalance, helper.app.CurrentState().Commission().GetCommissions().Send).String() != helper.app.CurrentState().Accounts().GetBalance(sender.address, types.USDTID).String() { + t.Fatalf("error sender usd balance") + } + if big.NewInt(0).Sub(initialBIPBalance, value).String() != helper.app.CurrentState().Accounts().GetBalance(sender.address, 0).String() { + t.Fatalf("error sender bip balance") + } + if value.String() != helper.app.CurrentState().Accounts().GetBalance(recipient.address, 0).String() { + t.Fatalf("error recipient bip balance") } } diff --git a/tests2/update_test.go b/tests/update_test.go similarity index 100% rename from tests2/update_test.go rename to tests/update_test.go diff --git a/tests2/send_test.go b/tests2/send_test.go deleted file mode 100644 index ae07b2d50..000000000 --- a/tests2/send_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package tests - -import ( - "github.com/MinterTeam/minter-go-node/coreV2/code" - "github.com/MinterTeam/minter-go-node/coreV2/transaction" - "github.com/MinterTeam/minter-go-node/coreV2/types" - "math/big" - "testing" -) - -func TestSend(t *testing.T) { - sender := CreateAddress() // create account for test - - helper := NewHelper(DefaultAppState(sender.address)) - - initialBIPBalance := helper.app.CurrentState().Accounts().GetBalance(sender.address, 0) - initialUSDTBalance := helper.app.CurrentState().Accounts().GetBalance(sender.address, types.USDTID) - - recipient := CreateAddress() // generate recipient - value := big.NewInt(1) - tx := helper.CreateTx(sender.privateKey, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient.address, - Value: value, - }, types.USDTID) - - _, results := helper.NextBlock(tx) - - for _, resp := range results { - if resp.Code != code.OK { - t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) - } - } - - if big.NewInt(0).Sub(initialUSDTBalance, helper.app.CurrentState().Commission().GetCommissions().Send).String() != helper.app.CurrentState().Accounts().GetBalance(sender.address, types.USDTID).String() { - t.Fatalf("error sender usd balance") - } - if big.NewInt(0).Sub(initialBIPBalance, value).String() != helper.app.CurrentState().Accounts().GetBalance(sender.address, 0).String() { - t.Fatalf("error sender bip balance") - } - if value.String() != helper.app.CurrentState().Accounts().GetBalance(recipient.address, 0).String() { - t.Fatalf("error recipient bip balance") - } -} diff --git a/tests/byz_test.go b/tests_old/byz_test.go similarity index 99% rename from tests/byz_test.go rename to tests_old/byz_test.go index 469918aa8..45f12eb4d 100644 --- a/tests/byz_test.go +++ b/tests_old/byz_test.go @@ -1,4 +1,4 @@ -package tests +package tests_old import ( "github.com/MinterTeam/minter-go-node/coreV2/types" diff --git a/tests/candidates_test.go b/tests_old/candidates_test.go similarity index 99% rename from tests/candidates_test.go rename to tests_old/candidates_test.go index 01cd6982b..96506e27c 100644 --- a/tests/candidates_test.go +++ b/tests_old/candidates_test.go @@ -1,4 +1,4 @@ -package tests +package tests_old import ( "math/big" diff --git a/tests/emission_test.go b/tests_old/emission_test.go similarity index 99% rename from tests/emission_test.go rename to tests_old/emission_test.go index 5265c9142..c8152732a 100644 --- a/tests/emission_test.go +++ b/tests_old/emission_test.go @@ -1,4 +1,4 @@ -package tests +package tests_old import ( "github.com/MinterTeam/minter-go-node/coreV2/state/swap" diff --git a/tests/example/counter/counter.go b/tests_old/example/counter/counter.go similarity index 100% rename from tests/example/counter/counter.go rename to tests_old/example/counter/counter.go diff --git a/tests_old/failed_test.go b/tests_old/failed_test.go new file mode 100644 index 000000000..f5fb3c6e4 --- /dev/null +++ b/tests_old/failed_test.go @@ -0,0 +1,1422 @@ +package tests_old + +// +//func TestFailedTxPayCommission(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "100", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "100", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "50", +// ID: 1, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "1", +// }, +// { +// Coin: 1, +// Value: "50", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: types.GetBaseCoinID(), +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(1)) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 107 { +// t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(big.NewInt(1)) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// // check commission balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "49" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "49", balance) +// } +// } +// +// // check pool reserves +// { +// reward := app.GetCurrentRewards() +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() +// if reward.Sign() != 1 || r1.String() != "51" || big.NewInt(0).Add(reward, r0).Cmp(reserve0) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "51", r0, r1, reward) +// } +// } +// +//} +// +//func TestFailedTxPayCommission_customPriceCoin(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(4e18).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "1", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: types.GetBaseCoinID(), +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(1)) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 107 { +// t.Fatalf("Response code is not error: %s, %d", response.Log, response.Code) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(big.NewInt(1)) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// // check commission balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "6000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "49", balance) +// } +// } +// +// // check pool reserves +// { +// reward := app.GetCurrentRewards() +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() +// if reward.Sign() != 1 || r1.String() != "6345678901234567890" || big.NewInt(0).Add(reward, r0).Cmp(reserve0) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "51", r0, r1, reward) +// } +// } +// +//} +// +//func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin_lessAvailable(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(4e18).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "10000000000000000000", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: 2, +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(0)) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 102 { +// t.Fatalf("Response code is not error: %s, %d", response.Log, response.Code) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(big.NewInt(0)) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// // check commission balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "10000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) +// } +// } +// +// // check pool reserves +// { +// reward := app.GetCurrentRewards() +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() +// if reward.String() != "10000000000000000000" || r1.String() != "2345678901234567890" { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "5000000000000000000000000000000000000", r0, r1, reward) +// } +// } +// +//} +// +//func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin_lessAvailable_withGasPrice(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(4e18).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "10000000000000000000", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: 2, +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(0), 50) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 102 { +// t.Fatalf("Response code is not error: %s, %d", response.Log, response.Code) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(big.NewInt(0)) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// // check commission balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "10000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) +// } +// } +// +// // check pool reserves +// { +// reward := app.GetCurrentRewards() +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() +// if reward.String() != "10000000000000000000" || r1.String() != "2345678901234567890" { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "5000000000000000000000000000000000000", r0, r1, reward) +// } +// } +// +//} +// +//func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin_withGasPrice(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(4e18).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "10000000000000000000000000000000000000", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: 2, +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(0), 50) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 102 { +// t.Fatalf("Response code is not error: %s, %d", response.Log, response.Code) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(helpers.StringToBigInt("5058076976788935588754051349077150287")) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// // check commission balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "10000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) +// } +// } +// +// // check pool reserves +// { +// reward := app.GetCurrentRewards() +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() +// if reward.String() != "4941923023211064411245948650922849713" || r1.String() != "2345678901234567890" { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "5000000000000000000000000000000000000", r0, r1, reward) +// } +// } +//} +// +//func TestFailedTxPayCommission_customPriceCoinAndPayBaseCoin(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(4e18).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "10000000000000000000000000000000000000", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: 2, +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(0), 1) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 102 { +// t.Fatalf("Response code is not error: %s, %d", response.Log, response.Code) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(helpers.StringToBigInt("6850582001541316700832722827411023323")) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// // check commission balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "10000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) +// } +// } +// +// // check pool reserves +// { +// reward := app.GetCurrentRewards() +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() +// if reward.String() != "3149417998458683299167277172588976677" || r1.String() != "2345678901234567890" { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "5000000000000000000000000000000000000", r0, r1, reward) +// } +// } +//} +// +//func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionToken(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }, types.Coin{ +// ID: 2, +// Name: "bbb", +// Symbol: types.StrToCoinBaseSymbol("BBB"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(4e18).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }, types.Pool{ +// Coin0: 0, +// Coin1: 2, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 2, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "1", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// { +// Coin: 2, +// Value: "10000000000000000000", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: types.GetBaseCoinID(), +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(2)) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 107 { +// t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(big.NewInt(1)) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "10000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) +// } +// } +// +// // check commission balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 2) +// if balance.String() != "6000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "6000000000000000000", balance) +// } +// } +// +// // check pool reserves +// { +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() +// if r0.String() != "5000000000000000000000000000000000000" || r1.String() != "2345678901234567890" { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s", "5000000000000000000000000000000000000", r0, r1) +// } +// } +// // check pool reserves +// { +// reward := app.GetCurrentRewards() +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 2).Reserves() +// if reward.Sign() != 1 || r1.String() != "6345678901234567890" || big.NewInt(0).Add(reward, r0).Cmp(reserve0) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "51", r0, r1, reward) +// } +// } +// +//} +// +//func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionToken_withGasPrice(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }, types.Coin{ +// ID: 2, +// Name: "bbb", +// Symbol: types.StrToCoinBaseSymbol("BBB"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(4e18).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }, types.Pool{ +// Coin0: 0, +// Coin1: 2, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 2, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "1", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// { +// Coin: 2, +// Value: "10000000000000000000", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: types.GetBaseCoinID(), +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(2), 2) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 107 { +// t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(big.NewInt(1)) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "10000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) +// } +// } +// +// // check commission balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 2) +// if balance.String() != "2000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "2000000000000000000", balance) +// } +// } +// +// // check pool reserves +// { +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() +// if r0.String() != "5000000000000000000000000000000000000" || r1.String() != "2345678901234567890" { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s", "5000000000000000000000000000000000000", r0, r1) +// } +// } +// +// // check pool reserves +// { +// reward := app.GetCurrentRewards() +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 2).Reserves() +// if reward.Sign() != 1 || r1.String() != "10345678901234567890" || big.NewInt(0).Add(reward, r0).Cmp(reserve0) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "1135407462159458011337752529693750189", r0, r1, reward) +// } +// } +//} +// +//func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionToken_withGasPrice_lessAvailable(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }, types.Coin{ +// ID: 2, +// Name: "bbb", +// Symbol: types.StrToCoinBaseSymbol("BBB"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(4e18).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }, types.Pool{ +// Coin0: 0, +// Coin1: 2, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 2, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "1", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// { +// Coin: 2, +// Value: "10000000000000000000", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: types.GetBaseCoinID(), +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(2), 50) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 107 { +// t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(big.NewInt(1)) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "10000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) +// } +// } +// +// // check commission balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 2) +// if balance.String() != "0" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "0", balance) +// } +// } +// +// // check pool reserves +// { +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 1).Reserves() +// if r0.String() != "5000000000000000000000000000000000000" || r1.String() != "2345678901234567890" { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s", "5000000000000000000000000000000000000", r0, r1) +// } +// } +// +// // check pool reserves +// { +// reward := app.GetCurrentRewards() +// r0, r1 := app.CurrentState().Swap().GetSwapper(0, 2).Reserves() +// if reward.Sign() != 1 || r1.String() != "12345678901234567890" || big.NewInt(0).Add(reward, r0).Cmp(reserve0) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s, %s and reward %s", "951541460730256157863947745387590710", r0, r1, reward) +// } +// } +//} +// +//func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCoin(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }, types.Coin{ +// ID: 2, +// Name: "bbb", +// Symbol: types.StrToCoinBaseSymbol("BBB"), +// Volume: "695664472679", +// Crr: 50, +// Reserve: "3149417998458693299167277172588976677", +// MaxSupply: "695664472679", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(4e18).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "1", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// { +// Coin: 2, +// Value: "695664472679", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: types.GetBaseCoinID(), +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(2)) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 107 { +// t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(big.NewInt(1)) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "10000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) +// } +// } +// +// // check commission balance +// { +// coin := app.CurrentState().Coins().GetCoin(2) +// balance := app.CurrentState().Accounts().GetBalance(address, 2) +// if balance.String() != "39200" && coin.Volume().String() != "39200" { +// t.Fatalf("volume or balance is not correct. Expected %s, got %s and coin volume %s", "49", balance, coin.Volume()) +// } +// +// if coin.Reserve().Cmp(helpers.StringToBigInt("10000000000000000000000")) == -1 { +// t.Fatalf("reserve is not correct. Got %s", coin.Reserve()) +// } +// } +// +//} +// +//func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCoin_withGasPrice(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }, types.Coin{ +// ID: 2, +// Name: "bbb", +// Symbol: types.StrToCoinBaseSymbol("BBB"), +// Volume: "695664472679", +// Crr: 50, +// Reserve: "4941923023211074411245948650922849713", +// MaxSupply: "695664472679", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(4e18).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "1", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// { +// Coin: 2, +// Value: "695664472679", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: types.GetBaseCoinID(), +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(2), 50) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 107 { +// t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(big.NewInt(1)) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "10000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) +// } +// } +// +// // check commission balance +// { +// coin := app.CurrentState().Coins().GetCoin(2) +// balance := app.CurrentState().Accounts().GetBalance(address, 2) +// if balance.String() != "31294" && coin.Volume().String() != "31294" { +// t.Fatalf("volume or balance is not correct. Expected %s, got %s and coin volume %s", "31294", balance, coin.Volume()) +// } +// +// if coin.Reserve().Cmp(helpers.StringToBigInt("10000000000000000000000")) == -1 { +// t.Fatalf("reserve is not correct. Got %s", coin.Reserve()) +// } +// } +// +//} +// +//func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCoin_withGasPrice_lessAvailable(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }, types.Coin{ +// ID: 2, +// Name: "bbb", +// Symbol: types.StrToCoinBaseSymbol("BBB"), +// Volume: "695664472679", +// Crr: 50, +// Reserve: "4941923023211074411245948650922849713", +// MaxSupply: "695664472679", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(4e18).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "1", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// { +// Coin: 2, +// Value: "95664472679", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }, +// types.Account{ +// Address: types.Address{}, +// Balance: []types.Balance{ +// { +// Coin: 2, +// Value: "600000000000", +// }, +// }, +// }, +// ) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: types.GetBaseCoinID(), +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(2), 50) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 107 { +// t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(big.NewInt(1)) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "10000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) +// } +// } +// +// // check commission balance +// { +// coin := app.CurrentState().Coins().GetCoin(2) +// balance := app.CurrentState().Accounts().GetBalance(address, 2) +// if balance.String() != "0" && coin.Volume().String() != "600000000000" { +// t.Fatalf("volume or balance is not correct. Expected %s, got %s and coin volume %s", "0", balance, coin.Volume()) +// } +// +// if coin.Reserve().Cmp(helpers.StringToBigInt("10000000000000000000000")) == -1 { +// t.Fatalf("reserve is not correct. Got %s", coin.Reserve()) +// } +// } +// +//} +// +//func TestFailedTxPayCommission_customPriceCoinAndCustomCommissionBancorReserveCoin_withGasPrice_lessReserve(t *testing.T) { +// address, pk := CreateAddress() // create account for test +// +// state := DefaultAppState() // generate default state +// +// state.Version = "v300" +// +// state.Coins = append(state.Coins, types.Coin{ +// ID: 1, +// Name: "aaa", +// Symbol: types.StrToCoinBaseSymbol("AAA"), +// Volume: "12345678901234567890", +// Crr: 0, +// Reserve: "0", +// MaxSupply: "12345678901234567890", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }, types.Coin{ +// ID: 2, +// Name: "bbb", +// Symbol: types.StrToCoinBaseSymbol("BBB"), +// Volume: "695664472679", +// Crr: 50, +// Reserve: "4941923023211074411245948650922849710", +// MaxSupply: "695664472679", +// Version: 0, +// OwnerAddress: nil, +// Mintable: false, +// Burnable: false, +// }) +// state.Commission.Coin = 1 +// state.Commission.FailedTx = big.NewInt(1e15).String() +// +// reserve0 := helpers.BipToPip(big.NewInt(5e18)) +// state.Pools = append(state.Pools, types.Pool{ +// Coin0: 0, +// Coin1: 1, +// Reserve0: reserve0.String(), +// Reserve1: "2345678901234567890", +// ID: 1, +// }) +// state.Accounts = append(state.Accounts, types.Account{ +// Address: address, +// Balance: []types.Balance{ +// { +// Coin: uint64(types.GetBaseCoinID()), +// Value: "1", +// }, +// { +// Coin: 1, +// Value: "10000000000000000000", +// }, +// { +// Coin: 2, +// Value: "95664472679", +// }, +// }, +// Nonce: 0, +// MultisigData: nil, +// }, +// types.Account{ +// Address: types.Address{}, +// Balance: []types.Balance{ +// { +// Coin: 2, +// Value: "600000000000", +// }, +// }, +// }, +// ) +// +// app := CreateApp(state) // create application +// SendBeginBlock(app, 1) // send BeginBlock +// +// recipient, _ := CreateAddress() // generate recipient +// tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ +// Coin: types.GetBaseCoinID(), +// To: recipient, +// Value: big.NewInt(100), +// }, types.CoinID(2), 50) +// +// response := SendTx(app, SignTx(pk, tx)) // compose and send tx +// +// // check that result is error +// if response.Code != 107 { +// t.Fatalf("Response code is not error: %s, %d, %s", response.Log, response.Code, response.Info) +// } +// +// SendEndBlock(app, 1) // send EndBlock +// SendCommit(app) // send Commit +// +// // check recipient's balance +// { +// balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) +// if balance.Cmp(big.NewInt(1)) != 0 { +// t.Fatalf("address balance is not correct. Expected %s, got %s", big.NewInt(1), balance) +// } +// } +// +// { +// balance := app.CurrentState().Accounts().GetBalance(address, 1) +// if balance.String() != "10000000000000000000" { +// t.Fatalf("address balance is not correct. Expected %s, got %s", "10000000000000000000", balance) +// } +// } +// +// // check commission balance +// { +// coin := app.CurrentState().Coins().GetCoin(2) +// balance := app.CurrentState().Accounts().GetBalance(address, 2) +// if balance.String() != "88294932483" && coin.Volume().String() != "688294932483" { +// t.Fatalf("volume or balance is not correct. Expected %s, got %s and coin volume %s", "88294932483", balance, coin.Volume()) +// } +// +// if coin.Reserve().Cmp(helpers.StringToBigInt("10000000000000000000000")) == -1 { +// t.Fatalf("reserve is not correct. Got %s", coin.Reserve()) +// } +// } +// +//} diff --git a/tests/helpers_test.go b/tests_old/helpers_test.go similarity index 99% rename from tests/helpers_test.go rename to tests_old/helpers_test.go index e9c018721..18254de10 100644 --- a/tests/helpers_test.go +++ b/tests_old/helpers_test.go @@ -1,4 +1,4 @@ -package tests +package tests_old import ( "crypto/ecdsa" diff --git a/tests/lock_test.go b/tests_old/lock_test.go similarity index 98% rename from tests/lock_test.go rename to tests_old/lock_test.go index 3e8c2c7b8..7a5cb9c33 100644 --- a/tests/lock_test.go +++ b/tests_old/lock_test.go @@ -1,4 +1,4 @@ -package tests +package tests_old import ( "github.com/MinterTeam/minter-go-node/coreV2/code" @@ -126,7 +126,7 @@ func TestLockTx(t *testing.T) { Balance: []types.Balance{ { Coin: uint64(types.GetBaseCoinID()), - Value: helpers.StringToBigInt("100010000000000000000").String(), + Value: helpers.StringToBigInt("100100000000000000000").String(), }, }, Nonce: 0, diff --git a/tests/move_test.go b/tests_old/move_test.go similarity index 98% rename from tests/move_test.go rename to tests_old/move_test.go index 0237a6d55..609f8599b 100644 --- a/tests/move_test.go +++ b/tests_old/move_test.go @@ -1,4 +1,4 @@ -package tests +package tests_old import ( "github.com/MinterTeam/minter-go-node/coreV2/types" diff --git a/tests/order_test.go b/tests_old/order_test.go similarity index 99% rename from tests/order_test.go rename to tests_old/order_test.go index cea9d8f66..6f01916c5 100644 --- a/tests/order_test.go +++ b/tests_old/order_test.go @@ -1,4 +1,4 @@ -package tests +package tests_old import ( "math/big" @@ -67,7 +67,7 @@ func TestOrder_checkBalanceGas0(t *testing.T) { tx := CreateTx(app, address, transaction.TypeBuySwapPool, transaction.BuySwapPoolDataV260{ Coins: []types.CoinID{1, 0}, ValueToBuy: helpers.StringToBigInt("39919492393318821938180"), - MaximumValueToSell: helpers.StringToBigInt("4000000000000000000"), // 3999999999999999999 + MaximumValueToSell: helpers.StringToBigInt("4004004004004004004"), // 3999999999999999999 }, 0) response := SendTx(app, SignTx(pk, tx)) // compose and send tx @@ -141,7 +141,7 @@ func TestOrder_checkBalanceGas1(t *testing.T) { tx := CreateTx(app, address, transaction.TypeBuySwapPool, transaction.BuySwapPoolDataV260{ Coins: []types.CoinID{1, 0}, ValueToBuy: helpers.StringToBigInt("39919492393318821938180"), - MaximumValueToSell: helpers.StringToBigInt("4000000000000000000"), // 3999999999999999999 + MaximumValueToSell: helpers.StringToBigInt("4004004004004004005"), // 3999999999999999999 }, 1) response := SendTx(app, SignTx(pk, tx)) // compose and send tx @@ -1000,8 +1000,8 @@ func TestOrder_buy(t *testing.T) { // check taker's balance { balance := app.CurrentState().Accounts().GetBalance(address, 1) - if balance.String() != big.NewInt(20000000000-10010000000).String() { - t.Fatalf("Taker balance is not correct. Expected %s, got %s", big.NewInt(20000000000-10010000000).String(), balance) + if balance.String() != big.NewInt(20000000000-10020020021).String() { + t.Fatalf("Taker balance is not correct. Expected %s, got %s", big.NewInt(20000000000-10020020021).String(), balance) } } @@ -1089,8 +1089,8 @@ func TestOrder_sell(t *testing.T) { // check seller's balance { balance1 := app.CurrentState().Accounts().GetBalance(seller, 1) - if balance1.String() != "10000000000" { - t.Fatalf("Saller balance is not correct. Expected %s, got %s", "10000000000", balance1) + if balance1.String() != "9990000000" { + t.Fatalf("Saller balance is not correct. Expected %s, got %s", "9990000000", balance1) } //balance0 := app.CurrentState().Accounts().GetBalance(seller, 0) @@ -2091,7 +2091,7 @@ func TestOrder_buy_10_more_a_lot(t *testing.T) { ID: 2, Name: "Test 2", Symbol: types.StrToCoinBaseSymbol("TEST2"), - Volume: "10010030214021935652033695", + Volume: "10020040254276211863897593", Crr: 0, Reserve: "0", MaxSupply: "90000000000000000000000000000", @@ -2133,7 +2133,7 @@ func TestOrder_buy_10_more_a_lot(t *testing.T) { }, { Coin: 2, - Value: helpers.StringToBigInt("10000030214021935652033695").String(), + Value: helpers.StringToBigInt("10010040254276211863897593").String(), }, }, Nonce: 0, diff --git a/tests/reward3_test.go b/tests_old/reward3_test.go similarity index 99% rename from tests/reward3_test.go rename to tests_old/reward3_test.go index e3dd1758d..d9bd4395e 100644 --- a/tests/reward3_test.go +++ b/tests_old/reward3_test.go @@ -1,4 +1,4 @@ -package tests +package tests_old import ( "github.com/MinterTeam/minter-go-node/coreV2/code" @@ -102,6 +102,7 @@ func TestReward_Simple(t *testing.T) { } func TestReward_X3Cmp(t *testing.T) { + t.Skip("move to tests_new") state := DefaultAppState() // generate default state stake := helpers.BipToPip(big.NewInt(10_000)) diff --git a/tests_old/send_test.go b/tests_old/send_test.go new file mode 100644 index 000000000..155667276 --- /dev/null +++ b/tests_old/send_test.go @@ -0,0 +1,68 @@ +package tests_old + +import ( + "math/big" + "testing" + + "github.com/MinterTeam/minter-go-node/coreV2/code" + "github.com/MinterTeam/minter-go-node/coreV2/transaction" + "github.com/MinterTeam/minter-go-node/coreV2/types" + "github.com/MinterTeam/minter-go-node/helpers" +) + +func TestSend(t *testing.T) { + address, pk := CreateAddress() // create account for test + + state := DefaultAppState() // generate default state + + // add address to genesis state + state.Accounts = append(state.Accounts, types.Account{ + Address: address, + Balance: []types.Balance{ + { + Coin: uint64(types.GetBaseCoinID()), + Value: helpers.StringToBigInt("100000000000000000000").String(), + }, + }, + Nonce: 0, + MultisigData: nil, + }) + + app := CreateApp(state) // create application + SendBeginBlock(app, 1) // send BeginBlock + + recipient, _ := CreateAddress() // generate recipient + value := big.NewInt(1) + + tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{ + Coin: types.GetBaseCoinID(), + To: recipient, + Value: value, + }, 0) + + response := SendTx(app, SignTx(pk, tx)) // compose and send tx + + // check that result is OK + if response.Code != code.OK { + t.Fatalf("Response code is not OK: %s, %d", response.Log, response.Code) + } + + SendEndBlock(app, 1) // send EndBlock + SendCommit(app) // send Commit + + // check recipient's balance + { + balance := app.CurrentState().Accounts().GetBalance(recipient, types.GetBaseCoinID()) + if balance.Cmp(value) != 0 { + t.Fatalf("Recipient balance is not correct. Expected %s, got %s", value, balance) + } + } + + // check sender's balance + { + balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID()) + if balance.String() != "99989999999999999999" { + t.Fatalf("Recipient balance is not correct. Expected %s, got %s", "98999999999999999999", balance) + } + } +} diff --git a/tests/swap3_test.go b/tests_old/swap3_test.go similarity index 99% rename from tests/swap3_test.go rename to tests_old/swap3_test.go index 0b0870baa..f49fa418f 100644 --- a/tests/swap3_test.go +++ b/tests_old/swap3_test.go @@ -1,4 +1,4 @@ -package tests +package tests_old import ( "github.com/MinterTeam/minter-go-node/coreV2/code" diff --git a/tests/votes_test.go b/tests_old/votes_test.go similarity index 99% rename from tests/votes_test.go rename to tests_old/votes_test.go index 5f8147bdf..e8c3929fd 100644 --- a/tests/votes_test.go +++ b/tests_old/votes_test.go @@ -1,4 +1,4 @@ -package tests +package tests_old import ( "math/big" From 3c1f886af0eb278cf8df83f45f4a74d820574187 Mon Sep 17 00:00:00 2001 From: klim0v Date: Thu, 2 Jun 2022 16:31:24 +0300 Subject: [PATCH 22/48] wip: test balance --- coreV2/transaction/executor_v250.go | 2 +- coreV2/transaction/executor_v3.go | 2 +- coreV2/transaction/transaction.go | 8 +- tests/balance_test.go | 271 ++++++++++++++++++++++++++++ tests/send_test.go | 135 -------------- 5 files changed, 277 insertions(+), 141 deletions(-) create mode 100644 tests/balance_test.go delete mode 100644 tests/send_test.go diff --git a/coreV2/transaction/executor_v250.go b/coreV2/transaction/executor_v250.go index b1caf6f90..c07f74e10 100644 --- a/coreV2/transaction/executor_v250.go +++ b/coreV2/transaction/executor_v250.go @@ -212,7 +212,7 @@ func (e *ExecutorV250) RunTx(context state.Interface, rawTx []byte, rewardPool * } if !isCheck && response.Code != 0 { - commissionInBaseCoin := big.NewInt(0).Add(commissions.FailedTx, big.NewInt(0).Mul(big.NewInt(tx.payloadAndServiceDataLen()), commissions.PayloadByte)) + commissionInBaseCoin := big.NewInt(0).Add(commissions.FailedTx, big.NewInt(0).Mul(big.NewInt(tx.PayloadAndServiceDataLen()), commissions.PayloadByte)) commissionInBaseCoin = tx.MulGasPrice(commissionInBaseCoin) if !commissions.Coin.IsBaseCoin() { diff --git a/coreV2/transaction/executor_v3.go b/coreV2/transaction/executor_v3.go index 439dd7bc5..9388d8e75 100644 --- a/coreV2/transaction/executor_v3.go +++ b/coreV2/transaction/executor_v3.go @@ -211,7 +211,7 @@ func (e *ExecutorV3) RunTx(context state.Interface, rawTx []byte, rewardPool *bi if !isCheck { if response.Code != 0 { - commissionInBaseCoin := big.NewInt(0).Add(commissions.FailedTx, big.NewInt(0).Mul(big.NewInt(tx.payloadAndServiceDataLen()), commissions.PayloadByte)) + commissionInBaseCoin := big.NewInt(0).Add(commissions.FailedTx, big.NewInt(0).Mul(big.NewInt(tx.PayloadAndServiceDataLen()), commissions.PayloadByte)) commissionInBaseCoin = tx.MulGasPrice(commissionInBaseCoin) if !commissions.Coin.IsBaseCoin() { diff --git a/coreV2/transaction/transaction.go b/coreV2/transaction/transaction.go index a9b2fde76..409ed5f91 100644 --- a/coreV2/transaction/transaction.go +++ b/coreV2/transaction/transaction.go @@ -211,8 +211,8 @@ func (tx *Transaction) Gas() int64 { if tx.CommissionCoin() != types.GetBaseCoinID() { base += 1 } - if tx.payloadAndServiceDataLen() != 0 { - base += tx.payloadAndServiceDataLen() / 1000 + if tx.PayloadAndServiceDataLen() != 0 { + base += tx.PayloadAndServiceDataLen() / 1000 } if tx.SignatureType == SigTypeMulti { base += int64(len(tx.multisig.Signatures)) * gasSign @@ -221,11 +221,11 @@ func (tx *Transaction) Gas() int64 { } func (tx *Transaction) Price(price *commission.Price) *big.Int { - payloadAndServiceData := big.NewInt(0).Mul(big.NewInt(tx.payloadAndServiceDataLen()), price.PayloadByte) + payloadAndServiceData := big.NewInt(0).Mul(big.NewInt(tx.PayloadAndServiceDataLen()), price.PayloadByte) return big.NewInt(0).Add(tx.decodedData.CommissionData(price), payloadAndServiceData) } -func (tx *Transaction) payloadAndServiceDataLen() int64 { +func (tx *Transaction) PayloadAndServiceDataLen() int64 { return int64(len(tx.Payload) + len(tx.ServiceData)) } diff --git a/tests/balance_test.go b/tests/balance_test.go new file mode 100644 index 000000000..4b1098c51 --- /dev/null +++ b/tests/balance_test.go @@ -0,0 +1,271 @@ +package tests + +import ( + "fmt" + "github.com/MinterTeam/minter-go-node/coreV2/code" + "github.com/MinterTeam/minter-go-node/coreV2/transaction" + "github.com/MinterTeam/minter-go-node/coreV2/types" + "math" + "math/big" + "testing" +) + +type diffBalance struct { + Coin types.CoinID + Value *big.Int +} + +func TestEditBalance(t *testing.T) { + sender := CreateAddress() // create account for test + + helper := NewHelper(DefaultAppState(sender.address)) + + // diffs == nil is wanted fail tx + var transactions []func() (tx transaction.Transaction, diffs []*diffBalance, desc string) + + for _, coinCommission := range []types.CoinID{types.BasecoinID, types.USDTID} { + coinCommission := coinCommission + + for _, coinAction := range []types.CoinID{types.BasecoinID, types.USDTID} { + coinAction := coinAction + { + recipient := CreateAddress() + value := big.NewInt(1) + transactions = append(transactions, func() (transaction.Transaction, []*diffBalance, string) { + return helper.CreateTx(sender.privateKey, transaction.SendData{ + Coin: coinAction, + To: recipient.address, + Value: value, + }, coinCommission), []*diffBalance{{ + Coin: coinAction, + Value: value}}, fmt.Sprintf("coinAction%dcoinCommission%d", coinAction, coinCommission) + }) + } + { + value := big.NewInt(1) + transactions = append(transactions, func() (transaction.Transaction, []*diffBalance, string) { + return helper.CreateTx(sender.privateKey, transaction.LockData{ + DueBlock: math.MaxUint32, + Coin: coinAction, + Value: value, + }, coinCommission), []*diffBalance{{ + Coin: coinAction, + Value: value}}, fmt.Sprintf("coinAction%dcoinCommission%d", coinAction, coinCommission) + }) + } + } + + { + value := big.NewInt(1e18) + transactions = append(transactions, func() (transaction.Transaction, []*diffBalance, string) { + return helper.CreateTx(sender.privateKey, transaction.SellSwapPoolDataV260{ + Coins: []types.CoinID{types.GetBaseCoinID(), types.USDTID}, + ValueToSell: value, + MinimumValueToBuy: big.NewInt(1), + }, types.USDTID), []*diffBalance{{ + Coin: types.GetBaseCoinID(), + Value: value}, { + Coin: types.USDTID, + Value: big.NewInt(0).Neg(big.NewInt(997001999999999)), + }}, "sell0" + }) + } + { + value := big.NewInt(1e15) + transactions = append(transactions, func() (transaction.Transaction, []*diffBalance, string) { + return helper.CreateTx(sender.privateKey, transaction.SellSwapPoolDataV260{ + Coins: []types.CoinID{types.USDTID, types.GetBaseCoinID()}, + ValueToSell: value, + MinimumValueToBuy: big.NewInt(1), + }, types.USDTID), []*diffBalance{{ + Coin: types.USDTID, + Value: value}, { + Coin: types.GetBaseCoinID(), + Value: big.NewInt(0).Neg(big.NewInt(997001999999998806)), + }}, "sell1993" + }) + } + { + value := big.NewInt(1e15) + transactions = append(transactions, func() (transaction.Transaction, []*diffBalance, string) { + return helper.CreateTx(sender.privateKey, transaction.BuySwapPoolDataV260{ + Coins: []types.CoinID{types.GetBaseCoinID(), types.USDTID}, + ValueToBuy: value, + MaximumValueToSell: big.NewInt(2e18), + }, types.USDTID), []*diffBalance{{ + Coin: types.GetBaseCoinID(), + Value: big.NewInt(1003007015031063931)}, { + Coin: types.USDTID, + Value: big.NewInt(0).Neg(value), + }}, "buy1993" + }) + } + { + value := big.NewInt(1e15) + transactions = append(transactions, func() (transaction.Transaction, []*diffBalance, string) { + return helper.CreateTx(sender.privateKey, transaction.BuySwapPoolDataV260{ + Coins: []types.CoinID{types.GetBaseCoinID(), types.USDTID}, + ValueToBuy: value, + MaximumValueToSell: big.NewInt(2e18), + }, types.USDTID), []*diffBalance{{ + Coin: types.GetBaseCoinID(), + Value: big.NewInt(1003007015031063931)}, { + Coin: types.USDTID, + Value: big.NewInt(0).Neg(value), + }}, "buy1993" + }) + } + { + value := big.NewInt(1e18) + transactions = append(transactions, func() (transaction.Transaction, []*diffBalance, string) { + return helper.CreateTx(sender.privateKey, transaction.BuySwapPoolDataV260{ + Coins: []types.CoinID{types.USDTID, types.GetBaseCoinID()}, + ValueToBuy: value, + MaximumValueToSell: big.NewInt(2e15), + }, types.USDTID), []*diffBalance{{ + Coin: types.USDTID, + Value: big.NewInt(1003007015031066)}, { + Coin: types.GetBaseCoinID(), + Value: big.NewInt(0).Neg(value), + }}, "buy0" + }) + } + + { + value := big.NewInt(1) + transactions = append(transactions, func() (transaction.Transaction, []*diffBalance, string) { + return helper.CreateTx(sender.privateKey, transaction.LockData{ + DueBlock: math.MaxUint32, + Coin: 404, + Value: value, + }, coinCommission), nil, fmt.Sprintf("coinAction%dcoinCommission%d", 404, coinCommission) + }) + } + { + recipient := CreateAddress() + value := big.NewInt(1) + transactions = append(transactions, func() (transaction.Transaction, []*diffBalance, string) { + return helper.CreateTx(sender.privateKey, transaction.SendData{ + Coin: 404, + To: recipient.address, + Value: value, + }, coinCommission), nil, fmt.Sprintf("coinAction%dcoinCommission%d", 404, coinCommission) + }) + } + } + + for _, txFunc := range transactions { + tx, diffs, description := txFunc() + t.Run("Type"+tx.Type.String()+""+description, func(t *testing.T) { + testBalance(t, NewHelper(DefaultAppState(sender.address)), tx, diffs) + }) + } +} + +func testBalance(t *testing.T, helper *Helper, tx transaction.Transaction, diffs []*diffBalance) { + sender, _ := tx.Sender() + + commissionPrice := tx.MulGasPrice(tx.Price(helper.app.CurrentState().Commission().GetCommissions())) + initialCommissionCoinBalance := helper.app.CurrentState().Accounts().GetBalance(sender, tx.CommissionCoin()) + + var initialBalances []*big.Int + for _, diff := range diffs { + initialBalances = append(initialBalances, helper.app.CurrentState().Accounts().GetBalance(sender, diff.Coin)) + } + + _, results := helper.NextBlock(tx) + + for _, resp := range results { + if diffs != nil { + if resp.Code != code.OK { + t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) + } + } else { + if resp.Code == code.OK { + t.Fatalf("Response code is OK, but wanted Error") + } + t.Run("failCommission", func(t *testing.T) { + var cmp = 0 + var failPrice = big.NewInt(1) + if tx.CommissionCoin() == types.USDTID { + commissions := helper.app.CurrentState().Commission().GetCommissions() + failPrice = tx.MulGasPrice(big.NewInt(0).Add(commissions.FailedTx, big.NewInt(0).Mul(big.NewInt(tx.PayloadAndServiceDataLen()), commissions.PayloadByte))) + } else { + cmp = 1 + } + if big.NewInt(0).Sub(initialCommissionCoinBalance, helper.app.CurrentState().Accounts().GetBalance(sender, tx.CommissionCoin())).Cmp(failPrice) != cmp { + t.Error("error sender usd balance") + } + }) + return + } + } + + var checkedCommissionCoin bool + for i, diff := range diffs { + t.Run(diff.Coin.String(), func(t *testing.T) { + var cmp = 0 + newBalance := big.NewInt(0).Sub(initialBalances[i], diff.Value) + if diff.Coin == tx.CommissionCoin() { + checkedCommissionCoin = true + if tx.CommissionCoin() != types.USDTID { + commissionPrice = big.NewInt(1) + cmp = 1 + } + newBalance.Sub(newBalance, commissionPrice) + } + if newBalance.Cmp(helper.app.CurrentState().Accounts().GetBalance(sender, diff.Coin)) != cmp { + t.Errorf("error sender CoinID-%d balance diff %s", diff.Coin, big.NewInt(0).Sub(newBalance, helper.app.CurrentState().Accounts().GetBalance(sender, diff.Coin))) + } + }) + + } + + t.Run("commissionCoin", func(t *testing.T) { + if !checkedCommissionCoin { + var cmp = 0 + if tx.CommissionCoin() != types.USDTID { + cmp = 1 + } + if big.NewInt(0).Sub(initialCommissionCoinBalance, helper.app.CurrentState().Accounts().GetBalance(sender, tx.CommissionCoin())).Cmp(commissionPrice) != cmp { + t.Error("error sender usd balance") + } + } + }) + +} + +func TestSend(t *testing.T) { + sender := CreateAddress() // create account for test + + helper := NewHelper(DefaultAppState(sender.address)) + + initialBIPBalance := helper.app.CurrentState().Accounts().GetBalance(sender.address, 0) + initialUSDTBalance := helper.app.CurrentState().Accounts().GetBalance(sender.address, types.USDTID) + + recipient := CreateAddress() // generate recipient + value := big.NewInt(1) + tx := helper.CreateTx(sender.privateKey, transaction.SendData{ + Coin: types.GetBaseCoinID(), + To: recipient.address, + Value: value, + }, types.USDTID) + + _, results := helper.NextBlock(tx) + + for _, resp := range results { + if resp.Code != code.OK { + t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) + } + } + + if big.NewInt(0).Sub(initialUSDTBalance, helper.app.CurrentState().Commission().GetCommissions().Send).String() != helper.app.CurrentState().Accounts().GetBalance(sender.address, types.USDTID).String() { + t.Fatalf("error sender usd balance") + } + if big.NewInt(0).Sub(initialBIPBalance, value).String() != helper.app.CurrentState().Accounts().GetBalance(sender.address, 0).String() { + t.Fatalf("error sender bip balance") + } + if value.String() != helper.app.CurrentState().Accounts().GetBalance(recipient.address, 0).String() { + t.Fatalf("error recipient bip balance") + } +} diff --git a/tests/send_test.go b/tests/send_test.go deleted file mode 100644 index e216aa5ef..000000000 --- a/tests/send_test.go +++ /dev/null @@ -1,135 +0,0 @@ -package tests - -import ( - "fmt" - "github.com/MinterTeam/minter-go-node/coreV2/code" - "github.com/MinterTeam/minter-go-node/coreV2/transaction" - "github.com/MinterTeam/minter-go-node/coreV2/types" - "math" - "math/big" - "testing" -) - -type diffBalance struct { - Coin types.CoinID - Value *big.Int -} - -func TestEditBalance(t *testing.T) { - sender := CreateAddress() // create account for test - - helper := NewHelper(DefaultAppState(sender.address)) - - var transactions []func() (transaction.Transaction, []*diffBalance) - - for _, coin := range []types.CoinID{types.BasecoinID, types.USDTID} { - coin := coin - { - recipient := CreateAddress() - value := big.NewInt(1) - transactions = append(transactions, func() (transaction.Transaction, []*diffBalance) { - return helper.CreateTx(sender.privateKey, transaction.SendData{ - Coin: coin, - To: recipient.address, - Value: value, - }, types.USDTID), []*diffBalance{{ - Coin: coin, - Value: value}} - }) - } - { - value := big.NewInt(1) - transactions = append(transactions, func() (transaction.Transaction, []*diffBalance) { - return helper.CreateTx(sender.privateKey, transaction.LockData{ - DueBlock: math.MaxUint32, - Coin: coin, - Value: value, - }, types.USDTID), []*diffBalance{{ - Coin: coin, - Value: value}} - }) - } - } - - for _, txFunc := range transactions { - tx, diffs := txFunc() - t.Run(fmt.Sprintf("TxType=%s,%#v", tx.Type, tx.GetDecodedData()), func(t *testing.T) { - testBalance(t, helper, tx, diffs) - }) - } -} -func testBalance(t *testing.T, helper *Helper, tx transaction.Transaction, diffs []*diffBalance) { - sender, _ := tx.Sender() - - initialCommissionCoinBalance := helper.app.CurrentState().Accounts().GetBalance(sender, tx.CommissionCoin()) - - var initialBalances []*big.Int - for _, diff := range diffs { - initialBalances = append(initialBalances, helper.app.CurrentState().Accounts().GetBalance(sender, diff.Coin)) - } - - _, results := helper.NextBlock(tx) - - for _, resp := range results { - if resp.Code != code.OK { - t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) - } - } - - var checkedCommissionCoin bool - for i, diff := range diffs { - newBalance := big.NewInt(0).Sub(initialBalances[i], diff.Value) - if diff.Coin == tx.CommissionCoin() { - if tx.CommissionCoin() != types.USDTID { - panic("unimplemented test commission coin not equal USDT") - } - checkedCommissionCoin = true - newBalance.Sub(newBalance, tx.MulGasPrice(tx.Price(helper.app.CurrentState().Commission().GetCommissions()))) - } - if newBalance.String() != helper.app.CurrentState().Accounts().GetBalance(sender, diff.Coin).String() { - t.Errorf("error sender CoinID-%d balance", diff.Coin) - } - } - - if !checkedCommissionCoin { - if big.NewInt(0).Sub(initialCommissionCoinBalance, tx.Price(helper.app.CurrentState().Commission().GetCommissions())).String() != helper.app.CurrentState().Accounts().GetBalance(sender, tx.CommissionCoin()).String() { - t.Error("error sender usd balance") - } - } - -} - -func TestSend(t *testing.T) { - sender := CreateAddress() // create account for test - - helper := NewHelper(DefaultAppState(sender.address)) - - initialBIPBalance := helper.app.CurrentState().Accounts().GetBalance(sender.address, 0) - initialUSDTBalance := helper.app.CurrentState().Accounts().GetBalance(sender.address, types.USDTID) - - recipient := CreateAddress() // generate recipient - value := big.NewInt(1) - tx := helper.CreateTx(sender.privateKey, transaction.SendData{ - Coin: types.GetBaseCoinID(), - To: recipient.address, - Value: value, - }, types.USDTID) - - _, results := helper.NextBlock(tx) - - for _, resp := range results { - if resp.Code != code.OK { - t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) - } - } - - if big.NewInt(0).Sub(initialUSDTBalance, helper.app.CurrentState().Commission().GetCommissions().Send).String() != helper.app.CurrentState().Accounts().GetBalance(sender.address, types.USDTID).String() { - t.Fatalf("error sender usd balance") - } - if big.NewInt(0).Sub(initialBIPBalance, value).String() != helper.app.CurrentState().Accounts().GetBalance(sender.address, 0).String() { - t.Fatalf("error sender bip balance") - } - if value.String() != helper.app.CurrentState().Accounts().GetBalance(recipient.address, 0).String() { - t.Fatalf("error recipient bip balance") - } -} From e9b080ff679893390654ac46f21f11ebf13f7bbc Mon Sep 17 00:00:00 2001 From: klim0v Date: Thu, 2 Jun 2022 18:39:20 +0300 Subject: [PATCH 23/48] wip: test validators --- tests/balance_test.go | 2 +- tests/helper_test.go | 45 +++++++++++++++++--- tests/update_test.go | 6 +-- tests/validator_test.go | 93 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 9 deletions(-) create mode 100644 tests/validator_test.go diff --git a/tests/balance_test.go b/tests/balance_test.go index 4b1098c51..80747290e 100644 --- a/tests/balance_test.go +++ b/tests/balance_test.go @@ -16,7 +16,7 @@ type diffBalance struct { } func TestEditBalance(t *testing.T) { - sender := CreateAddress() // create account for test + sender := CreateAddress() helper := NewHelper(DefaultAppState(sender.address)) diff --git a/tests/helper_test.go b/tests/helper_test.go index 15707fa9d..27a96e9dc 100644 --- a/tests/helper_test.go +++ b/tests/helper_test.go @@ -4,6 +4,8 @@ import ( "crypto/ecdsa" "fmt" "github.com/MinterTeam/minter-go-node/coreV2/state/coins" + "math/big" + "sort" "time" "github.com/MinterTeam/minter-go-node/cmd/utils" @@ -209,6 +211,9 @@ func DefaultAppState(addresses ...types.Address) types.AppState { Balance: []types.Balance{{ Coin: 0, Value: "1000000000000000000000000000000000", + }, { + Coin: 1, + Value: "1000000000000000000000000000000", }, { Coin: types.USDTID, Value: "1000000000000000000000000000000", @@ -219,17 +224,17 @@ func DefaultAppState(addresses ...types.Address) types.AppState { }) validators = append(validators, types.Validator{ TotalBipStake: "2000000000000000000000000000000000", - PubKey: types.Pubkey{byte(i)}, - AccumReward: "100", + PubKey: getValidatorAddress(i), + AccumReward: "0", AbsentTimes: types.NewBitArray(24), }) candidates = append(candidates, types.Candidate{ ID: uint64(i + 1), - RewardAddress: types.Address{byte(0), byte(i)}, + RewardAddress: getRewardAddress(i), OwnerAddress: addr, ControlAddress: addr, TotalBipStake: "2000000000000000000000000000000000", - PubKey: types.Pubkey{byte(i)}, + PubKey: getValidatorAddress(i), Commission: 10, Stakes: []types.Stake{{ Owner: addr, @@ -237,7 +242,7 @@ func DefaultAppState(addresses ...types.Address) types.AppState { Value: "1000000000000000000000000000000000", BipValue: "1000000000000000000000000000000000", }, { - Owner: types.Address{byte(i)}, + Owner: getCustomAddress(i), Coin: 0, Value: "1000000000000000000000000000000000", BipValue: "1000000000000000000000000000000000", @@ -272,6 +277,19 @@ func DefaultAppState(addresses ...types.Address) types.AppState { NextOrderID: 0, Accounts: accounts, Coins: []types.Coin{ + { + ID: 1, + Name: "Reserve Coin 1", + Symbol: types.StrToCoinSymbol("COIN1RES"), + Volume: fmt.Sprintf("%d000000000000000000000000000000", len(accounts)), + Crr: 50, + Reserve: "1000000000000000000000000000", + MaxSupply: coins.MaxCoinSupply().String(), + Version: 0, + OwnerAddress: &types.Address{}, + Mintable: false, + Burnable: false, + }, { ID: types.USDTID, Name: "USDT Eth", @@ -356,3 +374,20 @@ func DefaultAppState(addresses ...types.Address) types.AppState { Versions: nil, } } + +func getValidatorAddress(i int) types.Pubkey { + return types.Pubkey{byte(i)} +} + +func getRewardAddress(i int) (addr types.Address) { + copy(addr[:], big.NewInt(int64(i)).Bytes()) + return +} +func getCustomAddress(i int) (addr types.Address) { + bytes := big.NewInt(int64(i)).Bytes() + copy(addr[:], bytes) + sort.Slice(addr[:], func(i, j int) bool { + return false + }) + return +} diff --git a/tests/update_test.go b/tests/update_test.go index 48da11f7e..bc8d63298 100644 --- a/tests/update_test.go +++ b/tests/update_test.go @@ -74,17 +74,17 @@ func testUpdate(t *testing.T, valCount int, versions ...string) { t.Error("network is not updated") } - testBlock50(t, helper) + testBlocks(t, helper, 50) }) } } -func testBlock50(t *testing.T, helper *Helper) { +func testBlocks(t *testing.T, helper *Helper, countBlock uint64) { initial := helper.app.Height() c := make(chan struct{}) go func() { - for h := uint64(0); h <= initial+50; h, _ = helper.NextBlock() { + for h := uint64(0); h <= initial+countBlock; h, _ = helper.NextBlock() { } c <- struct{}{} }() diff --git a/tests/validator_test.go b/tests/validator_test.go new file mode 100644 index 000000000..83d90fa91 --- /dev/null +++ b/tests/validator_test.go @@ -0,0 +1,93 @@ +package tests + +import ( + "github.com/MinterTeam/minter-go-node/coreV2/code" + "github.com/MinterTeam/minter-go-node/coreV2/transaction" + "github.com/MinterTeam/minter-go-node/coreV2/types" + "math/big" + "testing" +) + +func TestEqualValidatorCmpBalances(t *testing.T) { + var addresses []types.Address + var users []*User + for i := 0; i < 10; i++ { + owner := CreateAddress() + users = append(users, owner) + addresses = append(addresses, owner.address) + } + + helper := NewHelper(DefaultAppState(addresses...)) + + var initialBalances = make(map[types.Address]map[types.CoinID]*big.Int) + for i, address := range addresses { + for _, addr := range []types.Address{address, getCustomAddress(i), getRewardAddress(i)} { + initialBalances[addr] = make(map[types.CoinID]*big.Int) + for _, balance := range helper.app.CurrentState().Accounts().GetBalances(addr) { + initialBalances[addr][balance.Coin.ID] = balance.Value + } + } + } + + t.Run("rewards", func(t *testing.T) { + testBlocks(t, helper, 50) + + for i, address := range addresses { + for _, addr := range []types.Address{address, getCustomAddress(i), getRewardAddress(i)} { + for coin, balance := range initialBalances[addr] { + if balance.String() != helper.app.CurrentState().Accounts().GetBalance(address, coin).String() { + t.Error("account"+address.String()+"balance is diff", balance) + } + } + } + } + }) + + t.Run("delegate", func(t *testing.T) { + delegatedCoin := types.CoinID(1) + { + var txs []transaction.Transaction + for i, delegator := range users { + txs = append(txs, helper.CreateTx(delegator.privateKey, transaction.DelegateDataV260{ + PubKey: getValidatorAddress(i), + Coin: delegatedCoin, + Value: initialBalances[delegator.address][delegatedCoin], + }, types.USDTID)) + } + + _, results := helper.NextBlock(txs...) + for _, resp := range results { + if resp.Code != code.OK { + t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) + } + } + } + testBlocks(t, helper, 50) + + var equalRewards = make(map[int]*big.Int) + for i, address := range addresses { + candidate := helper.app.CurrentState().Candidates().GetCandidate(getValidatorAddress(i)) + if candidate.Status != 2 { + t.Error("status is", candidate.Status) + } + delegateCoin1Balance := helper.app.CurrentState().Candidates().GetStakeValueOfAddress(getValidatorAddress(i), address, delegatedCoin) + if delegateCoin1Balance.String() != initialBalances[address][delegatedCoin].String() { + t.Errorf("validator "+getValidatorAddress(i).String()+" address "+address.String()+"delegate Coin1 Volume wanted %s, got %s", initialBalances[address][delegatedCoin].String(), delegateCoin1Balance) + } + for j, addr := range []types.Address{address, getCustomAddress(i), getRewardAddress(i)} { + rewardAddressBalance := helper.app.CurrentState().Candidates().GetStakeValueOfAddress(getValidatorAddress(i), addr, types.GetBaseCoinID()) + if equalRewards[j] == nil { + equalRewards[j] = rewardAddressBalance + } + if rewardAddressBalance.String() != equalRewards[j].String() { + t.Error("validator "+getValidatorAddress(i).String()+" address "+address.String()+" diff reward", i, rewardAddressBalance.String()) + } + } + balance := helper.app.CurrentState().Accounts().GetBalance(address, delegatedCoin).String() + if balance != "0" { + t.Error(helper.app.CurrentState().Coins().GetCoin(delegatedCoin).Symbol().String(), address.String(), "balance is", balance) + } + } + }) + +} From 6f209da252c7b96edc5fc29bbe12ceed2c4d67a1 Mon Sep 17 00:00:00 2001 From: klim0v Date: Thu, 2 Jun 2022 22:13:15 +0300 Subject: [PATCH 24/48] add net message for edit archived tokens --- coreV2/transaction/{mint_coin.go => mint_token.go} | 7 +++++++ 1 file changed, 7 insertions(+) rename coreV2/transaction/{mint_coin.go => mint_token.go} (95%) diff --git a/coreV2/transaction/mint_coin.go b/coreV2/transaction/mint_token.go similarity index 95% rename from coreV2/transaction/mint_coin.go rename to coreV2/transaction/mint_token.go index aa904ecaf..770c4a7c0 100644 --- a/coreV2/transaction/mint_coin.go +++ b/coreV2/transaction/mint_token.go @@ -54,6 +54,13 @@ func (data MintTokenData) basicCheck(tx *Transaction, context *state.CheckState) symbolInfo := context.Coins().GetSymbolInfo(coin.Symbol()) if coin.Version() != 0 || symbolInfo == nil || symbolInfo.OwnerAddress().Compare(sender) != 0 { var owner *string + if coin.Version() != 0 { + return &Response{ + Code: code.IsNotOwnerOfCoin, + Log: "Archived coin has no owner and cannot be changed", + Info: EncodeError(code.NewIsNotOwnerOfCoin(coin.Symbol().String(), nil)), + } + } if symbolInfo != nil && symbolInfo.OwnerAddress() != nil { own := symbolInfo.OwnerAddress().String() owner = &own From e84ae586ede52457d440c2847b08e4c6f3c2e7c9 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 3 Jun 2022 02:26:33 +0300 Subject: [PATCH 25/48] fix x3 rewards and tests --- coreV2/minter/blockchain.go | 10 +- coreV2/minter/minter.go | 3 + coreV2/state/validators/validators.go | 199 +++++++++++++++++++++++++- coreV2/transaction/executor_v3.go | 8 -- tests/balance_test.go | 10 +- tests/helper_test.go | 74 +++++++--- tests/update_test.go | 8 +- tests/validator_test.go | 130 +++++++++++++++++ 8 files changed, 403 insertions(+), 39 deletions(-) diff --git a/coreV2/minter/blockchain.go b/coreV2/minter/blockchain.go index 7917d576e..e70b12032 100644 --- a/coreV2/minter/blockchain.go +++ b/coreV2/minter/blockchain.go @@ -160,6 +160,7 @@ func NewMinterBlockchain(storages *utils.Storage, cfg *config.Config, ctx contex V310: {}, // hotfix V320: {}, V330: {}, + V340: {}, }, executor: GetExecutor(V3), } @@ -193,6 +194,7 @@ const ( // known update versions V310 = "v310" // hotfix V320 = "v320" // hotfix V330 = "v330" // hotfix + V340 = "v340" // hotfix ) func (blockchain *Blockchain) initState() { @@ -471,7 +473,9 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes. if height%blockchain.updateStakesAndPayRewardsPeriod == 0 { PayRewards := blockchain.stateDeliver.Validators.PayRewardsV3 if types.CurrentChainID == types.ChainTestnet { - if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h { + if h := blockchain.appDB.GetVersionHeight(V340); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix2 + } else if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h { PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix } else if h := blockchain.appDB.GetVersionHeight(V320); h > 0 && height > h { PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix @@ -479,7 +483,9 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes. PayRewards = blockchain.stateDeliver.Validators.PayRewardsV4 } } else { - if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h { + if h := blockchain.appDB.GetVersionHeight(V340); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix2 + } else if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h { if height < h+blockchain.updateStakesAndPayRewardsPeriod { excess := blockchain.stateDeliver.Candidates.FixStakesAfter10509400() blockchain.appDB.SetEmission(big.NewInt(0).Sub(blockchain.appDB.Emission(), excess)) diff --git a/coreV2/minter/minter.go b/coreV2/minter/minter.go index d3575378c..a8ee2da76 100644 --- a/coreV2/minter/minter.go +++ b/coreV2/minter/minter.go @@ -170,6 +170,9 @@ func (blockchain *Blockchain) UpdateVersions() []*appdb.Version { func (blockchain *Blockchain) GetVersionHeight(v string) uint64 { return blockchain.appDB.GetVersionHeight(v) } +func (blockchain *Blockchain) GetVersionName(h uint64) string { + return blockchain.appDB.GetVersionName(h) +} func (blockchain *Blockchain) GetEmission() *big.Int { emission := blockchain.appDB.Emission() diff --git a/coreV2/state/validators/validators.go b/coreV2/state/validators/validators.go index 902878f3c..6fd1b3a7a 100644 --- a/coreV2/state/validators/validators.go +++ b/coreV2/state/validators/validators.go @@ -431,7 +431,202 @@ func (v *Validators) PayRewardsV3(height uint64, period int64) (moreRewards *big return moreRewards } -// PayRewardsV5Fix distributes accumulated rewards between validator, delegators, DAO and developers addresses +// PayRewardsV5Fix2 distributes accumulated rewards between validator, delegators, DAO and developers addresses +func (v *Validators) PayRewardsV5Fix2(height uint64, period int64) (moreRewards *big.Int) { + moreRewards = big.NewInt(0) + + vals := v.GetValidators() + + calcReward, safeReward := v.bus.App().Reward() + var totalAccumRewards = big.NewInt(0) + for _, validator := range vals { + totalAccumRewards = totalAccumRewards.Add(totalAccumRewards, validator.GetAccumReward()) + } + + var totalStakes = big.NewInt(0) + if totalAccumRewards.Sign() != 1 { + for _, validator := range vals { + totalStakes = totalStakes.Add(totalStakes, validator.GetTotalBipStake()) + } + } + + for _, validator := range vals { + candidate := v.bus.Candidates().GetCandidate(validator.PubKey) + + totalReward := big.NewInt(0).Set(validator.GetAccumReward()) + remainder := big.NewInt(0).Set(validator.GetAccumReward()) + + // pay commission to DAO + + DAOReward := big.NewInt(0).Set(totalReward) + DAOReward.Mul(DAOReward, big.NewInt(int64(dao.Commission))) + DAOReward.Div(DAOReward, big.NewInt(100)) + + // pay commission to Developers + + DevelopersReward := big.NewInt(0).Set(totalReward) + DevelopersReward.Mul(DevelopersReward, big.NewInt(int64(developers.Commission))) + DevelopersReward.Div(DevelopersReward, big.NewInt(100)) + + totalReward.Sub(totalReward, DevelopersReward) + totalReward.Sub(totalReward, DAOReward) + remainder.Sub(remainder, DAOReward) + remainder.Sub(remainder, DevelopersReward) + + // pay commission to validator + validatorReward := big.NewInt(0).Set(totalReward) + validatorReward.Mul(validatorReward, big.NewInt(int64(candidate.Commission))) + validatorReward.Div(validatorReward, big.NewInt(100)) + totalReward.Sub(totalReward, validatorReward) + + candidate.AddUpdate(types.GetBaseCoinID(), validatorReward, validatorReward, candidate.RewardAddress) + v.bus.Checker().AddCoin(types.GetBaseCoinID(), validatorReward) + + remainder.Sub(remainder, validatorReward) + v.bus.Events().AddEvent(&eventsdb.RewardEvent{ + Role: eventsdb.RoleValidator.String(), + Address: candidate.RewardAddress, + Amount: validatorReward.String(), + ValidatorPubKey: validator.PubKey, + ForCoin: 0, + }) + + stakes := v.bus.Candidates().GetStakes(validator.PubKey) + for _, stake := range stakes { + if stake.BipValue.Sign() == 0 { + continue + } + + reward := big.NewInt(0).Set(totalReward) + reward.Mul(reward, stake.BipValue) + + reward.Div(reward, validator.GetTotalBipStake()) + + remainder.Sub(remainder, reward) + + safeRewardVariable := big.NewInt(0).Set(reward) + if validator.bus.Accounts().IsX3Mining(stake.Owner, height) { + if totalAccumRewards.Sign() == 1 && validator.GetAccumReward().Sign() == 1 { + safeRewards := big.NewInt(0).Mul(safeReward, big.NewInt(period)) + safeRewards.Mul(safeRewards, stake.BipValue) + safeRewards.Mul(safeRewards, big.NewInt(3)) + safeRewards.Mul(safeRewards, validator.GetAccumReward()) + safeRewards.Div(safeRewards, validator.GetTotalBipStake()) + safeRewards.Div(safeRewards, totalAccumRewards) + + taxDAOx3 := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(developers.Commission))), big.NewInt(100)) + taxDEVx3 := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(dao.Commission))), big.NewInt(100)) + + safeRewards.Sub(safeRewards, taxDAOx3) + safeRewards.Sub(safeRewards, taxDEVx3) + safeRewards.Sub(safeRewards, big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100))) + + calcRewards := big.NewInt(0).Mul(calcReward, big.NewInt(period)) + calcRewards.Mul(calcRewards, stake.BipValue) + calcRewards.Mul(calcRewards, validator.GetAccumReward()) + calcRewards.Div(calcRewards, validator.GetTotalBipStake()) + calcRewards.Div(calcRewards, totalAccumRewards) + + taxDAO := big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(developers.Commission))), big.NewInt(100)) + taxDEV := big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(dao.Commission))), big.NewInt(100)) + + calcRewards.Sub(calcRewards, taxDAO) + calcRewards.Sub(calcRewards, taxDEV) + calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100))) + + diffDAO := big.NewInt(0).Sub(taxDAOx3, taxDAO) + diffDEV := big.NewInt(0).Sub(taxDAOx3, taxDEV) + DAOReward.Add(DAOReward, diffDAO) + DevelopersReward.Add(DevelopersReward, diffDEV) + + moreRewards.Add(moreRewards, diffDAO) + moreRewards.Add(moreRewards, diffDEV) + + feeRewards := big.NewInt(0).Sub(reward, calcRewards) + safeRewardVariable.Set(big.NewInt(0).Add(safeRewards, feeRewards)) + } else if totalAccumRewards.Sign() != 1 && validator.GetAccumReward().Sign() != 1 { + safeRewards := big.NewInt(0).Mul(safeReward, big.NewInt(period)) + safeRewards.Mul(safeRewards, stake.BipValue) + safeRewards.Mul(safeRewards, big.NewInt(3)) + safeRewards.Div(safeRewards, totalStakes) + + taxDAO := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(developers.Commission))), big.NewInt(100)) + taxDEV := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(dao.Commission))), big.NewInt(100)) + + DAOReward.Add(DAOReward, taxDAO) + DevelopersReward.Add(DevelopersReward, taxDEV) + moreRewards.Add(moreRewards, taxDAO) + moreRewards.Add(moreRewards, taxDEV) + + safeRewards.Sub(safeRewards, taxDAO) + safeRewards.Sub(safeRewards, taxDEV) + + safeRewards.Sub(safeRewards, big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100))) + + safeRewardVariable.Set(safeRewards) + } + + if safeRewardVariable.Sign() < 1 { + continue + } + + moreRewards.Add(moreRewards, new(big.Int).Sub(safeRewardVariable, reward)) + } + + if safeRewardVariable.Sign() < 1 { + continue + } + + candidate.AddUpdate(types.GetBaseCoinID(), safeRewardVariable, safeRewardVariable, stake.Owner) + v.bus.Checker().AddCoin(types.GetBaseCoinID(), safeRewardVariable) + + v.bus.Events().AddEvent(&eventsdb.RewardEvent{ + Role: eventsdb.RoleDelegator.String(), + Address: stake.Owner, + Amount: safeRewardVariable.String(), + ValidatorPubKey: validator.PubKey, + ForCoin: uint64(stake.Coin), + }) + } + + { + candidate.AddUpdate(types.GetBaseCoinID(), DAOReward, DAOReward, dao.Address) + v.bus.Checker().AddCoin(types.GetBaseCoinID(), DAOReward) + v.bus.Events().AddEvent(&eventsdb.RewardEvent{ + Role: eventsdb.RoleDAO.String(), + Address: dao.Address, + Amount: DAOReward.String(), + ValidatorPubKey: validator.PubKey, + ForCoin: 0, + }) + } + + { + candidate.AddUpdate(types.GetBaseCoinID(), DevelopersReward, DevelopersReward, developers.Address) + v.bus.Checker().AddCoin(types.GetBaseCoinID(), DevelopersReward) + v.bus.Events().AddEvent(&eventsdb.RewardEvent{ + Role: eventsdb.RoleDevelopers.String(), + Address: developers.Address, + Amount: DevelopersReward.String(), + ValidatorPubKey: validator.PubKey, + ForCoin: 0, + }) + } + + validator.SetAccumReward(big.NewInt(0)) + + if remainder.Sign() != -1 { + v.bus.App().AddTotalSlashed(remainder) + } else { + panic(fmt.Sprintf("Negative remainder: %s", remainder.String())) + } + } + + return moreRewards +} + +// PayRewardsV5Fix +// Deprecated func (v *Validators) PayRewardsV5Fix(height uint64, period int64) (moreRewards *big.Int) { moreRewards = big.NewInt(0) @@ -532,7 +727,7 @@ func (v *Validators) PayRewardsV5Fix(height uint64, period int64) (moreRewards * calcRewards.Sub(calcRewards, taxDAO) calcRewards.Sub(calcRewards, taxDEV) - calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(developers.Commission+dao.Commission))), big.NewInt(100))) + //calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(developers.Commission+dao.Commission))), big.NewInt(100))) calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100))) diffDAO := big.NewInt(0).Sub(taxDAOx3, taxDAO) diff --git a/coreV2/transaction/executor_v3.go b/coreV2/transaction/executor_v3.go index 9388d8e75..49e33cf86 100644 --- a/coreV2/transaction/executor_v3.go +++ b/coreV2/transaction/executor_v3.go @@ -44,14 +44,6 @@ func (e *ExecutorV3) RunTx(context state.Interface, rawTx []byte, rewardPool *bi } } - if tx.Type == TypeLockStake && currentBlock <= 10197360 { - return Response{ - Code: code.Unavailable, - Log: "LockStake available from block 10197360 ", - Info: EncodeError(code.NewCustomCode(code.Unavailable)), - } - } - if tx.ChainID != types.CurrentChainID { return Response{ Code: code.WrongChainID, diff --git a/tests/balance_test.go b/tests/balance_test.go index 80747290e..c41370664 100644 --- a/tests/balance_test.go +++ b/tests/balance_test.go @@ -66,7 +66,7 @@ func TestEditBalance(t *testing.T) { Coin: types.GetBaseCoinID(), Value: value}, { Coin: types.USDTID, - Value: big.NewInt(0).Neg(big.NewInt(997001999999999)), + Value: big.NewInt(0).Neg(big.NewInt(997001999999999 - 7950111)), }}, "sell0" }) } @@ -81,7 +81,7 @@ func TestEditBalance(t *testing.T) { Coin: types.USDTID, Value: value}, { Coin: types.GetBaseCoinID(), - Value: big.NewInt(0).Neg(big.NewInt(997001999999998806)), + Value: big.NewInt(0).Neg(big.NewInt(997001999999998806 - 11930146541)), }}, "sell1993" }) } @@ -94,7 +94,7 @@ func TestEditBalance(t *testing.T) { MaximumValueToSell: big.NewInt(2e18), }, types.USDTID), []*diffBalance{{ Coin: types.GetBaseCoinID(), - Value: big.NewInt(1003007015031063931)}, { + Value: big.NewInt(1003007015031063931 + 8028065413)}, { Coin: types.USDTID, Value: big.NewInt(0).Neg(value), }}, "buy1993" @@ -109,7 +109,7 @@ func TestEditBalance(t *testing.T) { MaximumValueToSell: big.NewInt(2e18), }, types.USDTID), []*diffBalance{{ Coin: types.GetBaseCoinID(), - Value: big.NewInt(1003007015031063931)}, { + Value: big.NewInt(1003007015031063931 + 8028065413)}, { Coin: types.USDTID, Value: big.NewInt(0).Neg(value), }}, "buy1993" @@ -124,7 +124,7 @@ func TestEditBalance(t *testing.T) { MaximumValueToSell: big.NewInt(2e15), }, types.USDTID), []*diffBalance{{ Coin: types.USDTID, - Value: big.NewInt(1003007015031066)}, { + Value: big.NewInt(1003007015031066 + 12032073)}, { Coin: types.GetBaseCoinID(), Value: big.NewInt(0).Neg(value), }}, "buy0" diff --git a/tests/helper_test.go b/tests/helper_test.go index 27a96e9dc..7c9942d74 100644 --- a/tests/helper_test.go +++ b/tests/helper_test.go @@ -4,6 +4,7 @@ import ( "crypto/ecdsa" "fmt" "github.com/MinterTeam/minter-go-node/coreV2/state/coins" + "github.com/MinterTeam/minter-go-node/helpers" "math/big" "sort" "time" @@ -33,7 +34,20 @@ func CreateAppDefault(state types.AppState) *minter.Blockchain { return CreateApp(state, updateStakePeriod, expiredOrdersPeriod, 999) } -func CreateApp(state types.AppState, updateStakePeriod, expiredOrdersPeriod uint64, initialHeightOmitempty int64) *minter.Blockchain { +func CreateApp(state types.AppState, updateStakePeriod, expiredOrdersPeriod uint64, initialHeightOmitempty uint64) *minter.Blockchain { + + var lastUpdateHeight uint64 + var votes []types.UpdateVote + for i, vote := range state.UpdateVotes { + lastUpdateHeight = initialHeightOmitempty + uint64(i) + 2 + votes = append(votes, types.UpdateVote{ + Height: lastUpdateHeight, + Votes: vote.Votes, + Version: vote.Version, + }) + } + state.UpdateVotes = votes + jsonState, err := amino.MarshalJSON(state) if err != nil { panic(err) @@ -52,10 +66,16 @@ func CreateApp(state types.AppState, updateStakePeriod, expiredOrdersPeriod uint Time: time.Unix(0, 0), ChainId: "test1", Validators: updates, - InitialHeight: initialHeightOmitempty, + InitialHeight: int64(initialHeightOmitempty), AppStateBytes: jsonState, }) + for i := initialHeightOmitempty; i < lastUpdateHeight+1; i++ { + SendBeginBlock(app, time.Unix(int64(lastUpdateHeight), 0)) + SendEndBlock(app) + SendCommit(app) + } + return app } @@ -199,6 +219,8 @@ func CreateAddress() *User { return &User{crypto.PubkeyToAddress(pk.PublicKey), pk} } +var initialBIPStake = helpers.StringToBigInt("1000000000000000000000000000000000") + // DefaultAppState returns new AppState with some predefined values func DefaultAppState(addresses ...types.Address) types.AppState { var accounts = make([]types.Account, 0, len(addresses)) @@ -210,20 +232,20 @@ func DefaultAppState(addresses ...types.Address) types.AppState { Address: addr, Balance: []types.Balance{{ Coin: 0, - Value: "1000000000000000000000000000000000", + Value: "100000000000000000000000000", }, { Coin: 1, - Value: "1000000000000000000000000000000", + Value: "100000000000000000000000", }, { Coin: types.USDTID, - Value: "1000000000000000000000000000000", + Value: "100000000000000000000000", }}, Nonce: 0, MultisigData: nil, LockStakeUntilBlock: 0, }) validators = append(validators, types.Validator{ - TotalBipStake: "2000000000000000000000000000000000", + TotalBipStake: "200000000000000000000000000", PubKey: getValidatorAddress(i), AccumReward: "0", AbsentTimes: types.NewBitArray(24), @@ -233,25 +255,26 @@ func DefaultAppState(addresses ...types.Address) types.AppState { RewardAddress: getRewardAddress(i), OwnerAddress: addr, ControlAddress: addr, - TotalBipStake: "2000000000000000000000000000000000", + TotalBipStake: "200000000000000000000000000", PubKey: getValidatorAddress(i), Commission: 10, Stakes: []types.Stake{{ Owner: addr, Coin: 0, - Value: "1000000000000000000000000000000000", - BipValue: "1000000000000000000000000000000000", + Value: initialBIPStake.String(), + BipValue: initialBIPStake.String(), }, { Owner: getCustomAddress(i), Coin: 0, - Value: "1000000000000000000000000000000000", - BipValue: "1000000000000000000000000000000000", + Value: "100000000000000000000000000", + BipValue: "100000000000000000000000000", }}, + //Updates: nil, Updates: []types.Stake{{ Owner: addr, Coin: 0, - Value: "500000000000000000000000000000000", - BipValue: "500000000000000000000000000000000", + Value: "50000000000000000000000000", + BipValue: "50000000000000000000000000", }}, Status: 2, JailedUntil: 0, @@ -259,6 +282,19 @@ func DefaultAppState(addresses ...types.Address) types.AppState { }) } + var votes []types.UpdateVote + for _, v := range []string{minter.V310, minter.V320, minter.V330, minter.V340} { + vote := types.UpdateVote{ + Height: 0, + Votes: nil, + Version: v, + } + for i := range addresses { + vote.Votes = append(vote.Votes, getValidatorAddress(i)) + } + votes = append(votes, vote) + } + return types.AppState{ Note: "test1", Validators: validators, @@ -269,8 +305,8 @@ func DefaultAppState(addresses ...types.Address) types.AppState { Pools: []types.Pool{{ Coin0: 0, Coin1: types.USDTID, - Reserve0: "1000000000000000000000000000000000", - Reserve1: "1000000000000000000000000000000", + Reserve0: "100000000000000000000000000", + Reserve1: "100000000000000000000000", ID: 1, Orders: nil, }}, @@ -281,9 +317,9 @@ func DefaultAppState(addresses ...types.Address) types.AppState { ID: 1, Name: "Reserve Coin 1", Symbol: types.StrToCoinSymbol("COIN1RES"), - Volume: fmt.Sprintf("%d000000000000000000000000000000", len(accounts)), + Volume: fmt.Sprintf("%d00000000000000000000000", len(accounts)), Crr: 50, - Reserve: "1000000000000000000000000000", + Reserve: "100000000000000000000", MaxSupply: coins.MaxCoinSupply().String(), Version: 0, OwnerAddress: &types.Address{}, @@ -294,7 +330,7 @@ func DefaultAppState(addresses ...types.Address) types.AppState { ID: types.USDTID, Name: "USDT Eth", Symbol: types.StrToCoinSymbol("USDTE"), - Volume: fmt.Sprintf("%d000000000000000000000000000000", len(accounts)+1), + Volume: fmt.Sprintf("%d00000000000000000000000", len(accounts)+1), Crr: 0, Reserve: "0", MaxSupply: coins.MaxCoinSupply().String(), @@ -358,7 +394,7 @@ func DefaultAppState(addresses ...types.Address) types.AppState { Lock: "200000000000000", }, CommissionVotes: nil, - UpdateVotes: nil, + UpdateVotes: votes, UsedChecks: nil, MaxGas: 0, TotalSlashed: "0", diff --git a/tests/update_test.go b/tests/update_test.go index bc8d63298..293ef3968 100644 --- a/tests/update_test.go +++ b/tests/update_test.go @@ -14,7 +14,7 @@ import ( func TestUpdate(t *testing.T) { for _, valCount := range []int{1, 4, 20, 50, 70} { t.Run(fmt.Sprintf("%dvals", valCount), func(t *testing.T) { - testUpdate(t, valCount, minter.V310, minter.V320, minter.V330) + testUpdate(t, valCount, minter.V310, minter.V320, minter.V330, minter.V340) }) } } @@ -28,7 +28,9 @@ func testUpdate(t *testing.T, valCount int, versions ...string) { addresses = append(addresses, voter.address) } - helper := NewHelper(DefaultAppState(addresses...)) + state := DefaultAppState(addresses...) + state.UpdateVotes = nil + helper := NewHelper(state) for _, version := range versions { t.Run(version, func(t *testing.T) { @@ -51,7 +53,7 @@ func testUpdate(t *testing.T, valCount int, versions ...string) { } updatedHeight := height - for h := uint64(0); h <= updatedHeight+1; h, _ = helper.NextBlock() { + for h := uint64(0); h <= updatedHeight+2; h, _ = helper.NextBlock() { } var updated bool diff --git a/tests/validator_test.go b/tests/validator_test.go index 83d90fa91..481f1fb8c 100644 --- a/tests/validator_test.go +++ b/tests/validator_test.go @@ -2,8 +2,11 @@ package tests import ( "github.com/MinterTeam/minter-go-node/coreV2/code" + "github.com/MinterTeam/minter-go-node/coreV2/minter" "github.com/MinterTeam/minter-go-node/coreV2/transaction" "github.com/MinterTeam/minter-go-node/coreV2/types" + "github.com/MinterTeam/minter-go-node/helpers" + abciTypes "github.com/tendermint/tendermint/abci/types" "math/big" "testing" ) @@ -91,3 +94,130 @@ func TestEqualValidatorCmpBalances(t *testing.T) { }) } + +func TestX3Rewards(t *testing.T) { + var addresses []types.Address + var users []*User + for i := 0; i < 20; i++ { + owner := CreateAddress() + users = append(users, owner) + addresses = append(addresses, owner.address) + } + + helper := NewHelper(DefaultAppState(addresses...)) + if helper.app.GetVersionName(helper.app.Height()) != minter.V340 { + t.Fatalf("version want %s, got %s", minter.V340, helper.app.GetVersionName(helper.app.Height())) + } + if r1, r3 := helper.app.CurrentState().App().Reward(); r1.Cmp(r3) != 0 { + t.Fatal("rewards diff", r1, r3) + } + + { + delegatedCoin := types.CoinID(1) + var initialBalances = make(map[types.Address]*big.Int) + for _, address := range addresses { + initialBalances[address] = helper.app.CurrentState().Accounts().GetBalance(address, delegatedCoin) + } + { + //var txs []transaction.Transaction + for i, delegator := range users { + _, results := helper.NextBlock(helper.CreateTx(delegator.privateKey, transaction.DelegateDataV260{ + PubKey: getValidatorAddress(i), + Coin: delegatedCoin, + Value: initialBalances[delegator.address], + }, types.USDTID)) + for _, resp := range results { + if resp.Code != code.OK { + t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) + } + } + } + } + } + + for h := uint64(1); h%helper.app.UpdateStakesAndPayRewardsPeriod() != 0; h, _ = helper.NextBlock() { + } + + for h := uint64(1); h%helper.app.UpdateStakesAndPayRewardsPeriod() != 0; h, _ = helper.NextBlock() { + } + + { + h := helper.app.Height() + if len(helper.app.GetEventsDB().LoadEvents(uint32(h))) < 5*len(addresses) { + t.Fatalf("reward events want more than %d, got %d", 5*len(addresses), len(helper.app.GetEventsDB().LoadEvents(uint32(h)))) + } + } + + { + lastJ := 0 + for j, user := range users { + var txs []transaction.Transaction + for i, delegator := range users { + if lastJ <= i { + delegatedBalance := big.NewInt(0).Sub(helper.app.CurrentState().Candidates().GetStakeValueOfAddress(getValidatorAddress(i), delegator.address, types.GetBaseCoinID()), initialBIPStake) + txs = append(txs, helper.CreateTx(delegator.privateKey, transaction.UnbondDataV3{ + PubKey: getValidatorAddress(i), + Coin: types.GetBaseCoinID(), + Value: delegatedBalance, + }, types.USDTID)) + lastJ = j + 1 + } + } + _, results := helper.NextBlock(txs...) + for _, resp := range results { + if resp.Code != code.OK { + t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) + } + } + + { + h, results := helper.NextBlock(helper.CreateTx(user.privateKey, transaction.LockStakeData{}, types.USDTID)) + for _, resp := range results { + if resp.Code != code.OK { + t.Fatalf("Response code is not OK: %d, %s", resp.Code, resp.Log) + } + } + + for ; h%helper.app.UpdateStakesAndPayRewardsPeriod() != 0; h, _ = helper.NextBlock() { + } + + if lastJ > 0 && lastJ < len(users) { + quo := big.NewFloat(0).Quo( + big.NewFloat(0).SetInt(big.NewInt(0).Sub( + helper.app.CurrentState().Candidates().GetStakeValueOfAddress(getValidatorAddress(lastJ-1), users[lastJ-1].address, types.GetBaseCoinID()), + initialBIPStake)), + big.NewFloat(0).SetInt(big.NewInt(0).Sub( + helper.app.CurrentState().Candidates().GetStakeValueOfAddress(getValidatorAddress(lastJ), users[lastJ].address, types.GetBaseCoinID()), + initialBIPStake))).Text('f', 1) + if quo != "3.0" { + t.Errorf("rewards want x3, got %s", quo) + } + } + if lastJ > 1 && lastJ <= len(users) { + quo := big.NewFloat(0).Quo( + big.NewFloat(0).SetInt(big.NewInt(0).Sub( + helper.app.CurrentState().Candidates().GetStakeValueOfAddress(getValidatorAddress(lastJ-2), users[lastJ-2].address, types.GetBaseCoinID()), + initialBIPStake)), + big.NewFloat(0).SetInt(big.NewInt(0).Sub( + helper.app.CurrentState().Candidates().GetStakeValueOfAddress(getValidatorAddress(lastJ-1), users[lastJ-1].address, types.GetBaseCoinID()), + initialBIPStake))).Text('f', 1) + if quo != "2.0" { + t.Errorf("diff stakes want x2, got %s", quo) + } + } + + } + } + } + +} + +func getCommissionFromTags(event abciTypes.Event) *big.Int { + for _, attr := range event.Attributes { + if string(attr.Key) == "tx.commission_in_base_coin" { + return helpers.StringToBigInt(string(attr.Value)) + } + } + + return big.NewInt(0) +} From 73d225f452883ad0c5d23807002087b2ed700dde Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 3 Jun 2022 02:32:32 +0300 Subject: [PATCH 26/48] update version and CHANGELOG.md --- CHANGELOG.md | 13 +++++++++++++ version/version.go | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 152a39086..24e330b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## [v3.4.0](https://github.com/MinterTeam/minter-go-node/tree/v3.4.0) + +[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.3.0...v3.4.0) + +### Added + +- API method: `waitlist_all` +- Indexed tags to search for transactions by order + +### Fixed + +- Calculation of x3 rewards + ## [v3.3.0](https://github.com/MinterTeam/minter-go-node/tree/v3.3.0) [Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.2.0...v3.3.0) diff --git a/version/version.go b/version/version.go index e0f055ef5..cd04248af 100755 --- a/version/version.go +++ b/version/version.go @@ -7,7 +7,7 @@ const ( var ( // Version must be a string because scripts like dist.sh read this file. - Version = "3.3.1" + Version = "3.4.0" // GitCommit is the current HEAD set using ldflags. GitCommit string From 32bccc28ae3b0d388c76f5caf4c1b7803eec5750 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 3 Jun 2022 02:39:09 +0300 Subject: [PATCH 27/48] update gateway --- go.mod | 12 ++++++------ go.sum | 31 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 917bd8b1f..9fbfb81a4 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/MinterTeam/minter-go-node go 1.17 require ( - github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220521100308-a6e3f89cfa42 + github.com/MinterTeam/node-grpc-gateway v1.7.0 github.com/btcsuite/btcd v0.22.0-beta github.com/c-bata/go-prompt v0.2.5 github.com/cosmos/cosmos-sdk v0.44.5 @@ -14,7 +14,7 @@ require ( github.com/gorilla/handlers v1.5.1 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 - github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0 + github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 github.com/marcusolsson/tui-go v0.4.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.12.1 @@ -30,8 +30,8 @@ require ( golang.org/x/crypto v0.0.0-20211202192323-5770296d904e golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 - google.golang.org/grpc v1.45.0 - google.golang.org/protobuf v1.27.1 + google.golang.org/grpc v1.46.2 + google.golang.org/protobuf v1.28.0 ) replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 @@ -98,8 +98,8 @@ require ( go.etcd.io/bbolt v1.3.6 // indirect golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect golang.org/x/text v0.3.7 // indirect - google.golang.org/genproto v0.0.0-20220317150908-0efb43f6373e // indirect + google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect gopkg.in/ini.v1 v1.66.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index a8473741f..c1e17a09a 100644 --- a/go.sum +++ b/go.sum @@ -85,8 +85,8 @@ github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jB github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY= github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= -github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220521100308-a6e3f89cfa42 h1:05lQGVNDMxRGhndk1V/Txdm5ATzVlzNmwJOAhUl1XU4= -github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220521100308-a6e3f89cfa42/go.mod h1:aXWn+ewPqPGbnHbKEZzNik3motgWpFkT7LFTcBWvlHI= +github.com/MinterTeam/node-grpc-gateway v1.7.0 h1:EN4GsIVh+thloOUKTWJYEeHTkiTx941mG/t6u1xmwiA= +github.com/MinterTeam/node-grpc-gateway v1.7.0/go.mod h1:ABl5Sn4RJobzU07kbQ2xi1yzRTMFYHMpgzixTBaN0zI= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= @@ -287,6 +287,7 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.m github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/go-control-plane v0.10.1/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.6.2/go.mod h1:2t7qjJNvHPx8IjnBOzl9E9/baC+qXE/TeeyBRzgJDws= github.com/ethereum/go-ethereum v1.9.25/go.mod h1:vMkFiYLHI4tgPw4k2j4MHKoovchFE8plZ0M9VMk4/oM= @@ -419,8 +420,8 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= -github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64= @@ -484,8 +485,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0 h1:ESEyqQqXXFIcImj/BE8oKEX37Zsuceb2cZI+EL/zNCY= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0/go.mod h1:XnLCLFp3tjoZJszVKjfpyAK6J8sYIcQXWQxmqLWF21I= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 h1:BGNSrTRW4rwfhJiFwvwF4XQ0Y72Jj9YEgxVrtovbD5o= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3/go.mod h1:VHn7KgNsRriXa4mcgtkpR00OXyQY6g67JWMvn+R27A4= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= github.com/gtank/merlin v0.1.1 h1:eQ90iG7K9pOhtereWsmyRJ6RAwcP4tHTDBHXNg+u5is= @@ -1189,7 +1190,7 @@ golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= +golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1392,7 +1393,6 @@ golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= @@ -1508,8 +1508,8 @@ google.golang.org/genproto v0.0.0-20211028162531-8db9c33dc351/go.mod h1:5CzLGKJ6 google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20220317150908-0efb43f6373e h1:fNKDNuUyC4WH+inqDMpfXDdfvwfYILbsX+oskGZ8hxg= -google.golang.org/genproto v0.0.0-20220317150908-0efb43f6373e/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E= +google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd h1:e0TwkXOdbnH/1x5rc5MZ/VYyiZ4v+RdVfrGMqEwT68I= +google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= @@ -1545,8 +1545,10 @@ google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9K google.golang.org/grpc v1.40.1/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= -google.golang.org/grpc v1.45.0 h1:NEpgUqV3Z+ZjkqMsxMg11IaDrXY4RY6CQukSGK0uI1M= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= +google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ= +google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= @@ -1561,8 +1563,9 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 h1:FVCohIoYO7IJoDDVpV2pdq7SgrMH6wHnuTyrdrxJNoY= gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= @@ -1599,8 +1602,9 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -1617,5 +1621,4 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= From 6dd2b5b201ed38092bb1191f14f041f0b0196ed3 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 3 Jun 2022 03:09:40 +0300 Subject: [PATCH 28/48] update old tests --- coreV2/state/candidates_test.go | 2 +- coreV2/state/state.go | 1 + coreV2/state/state_test.go | 2 +- coreV2/transaction/buy_coin_test.go | 2 +- coreV2/transaction/edit_coin_owner_test.go | 8 ++++---- coreV2/transaction/set_halt_block_test.go | 14 +++++++------- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/coreV2/state/candidates_test.go b/coreV2/state/candidates_test.go index e3772b7ac..bf4139f42 100644 --- a/coreV2/state/candidates_test.go +++ b/coreV2/state/candidates_test.go @@ -540,7 +540,7 @@ func TestRecalculateStakes(t *testing.T) { } func getState() *State { - s, err := NewState(0, db.NewMemDB(), &eventsdb.MockEvents{}, 1, 1, 0) + s, err := NewStateV3(0, db.NewMemDB(), &eventsdb.MockEvents{}, 1, 1, 0) if err != nil { panic(err) diff --git a/coreV2/state/state.go b/coreV2/state/state.go index bd7f893ca..894ed61de 100644 --- a/coreV2/state/state.go +++ b/coreV2/state/state.go @@ -138,6 +138,7 @@ func (s *State) Bus() *bus.Bus { func (s *State) isValue_State() {} +// Deprecated func NewState(height uint64, db db.DB, events eventsdb.IEventsDB, cacheSize int, keepLastStates int64, initialVersion uint64) (*State, error) { iavlTree, err := tree.NewMutableTree(height, db, cacheSize, initialVersion) if err != nil { diff --git a/coreV2/state/state_test.go b/coreV2/state/state_test.go index 46c7e130b..96ed8dcea 100644 --- a/coreV2/state/state_test.go +++ b/coreV2/state/state_test.go @@ -18,7 +18,7 @@ func TestStateExport(t *testing.T) { t.Parallel() height := uint64(0) - state, err := NewState(height, db.NewMemDB(), &eventsdb.MockEvents{}, 1, 2, 0) + state, err := NewStateV3(height, db.NewMemDB(), &eventsdb.MockEvents{}, 1, 2, 0) if err != nil { log.Panic("Cannot create state") } diff --git a/coreV2/transaction/buy_coin_test.go b/coreV2/transaction/buy_coin_test.go index 28117106f..53c42ff28 100644 --- a/coreV2/transaction/buy_coin_test.go +++ b/coreV2/transaction/buy_coin_test.go @@ -89,7 +89,7 @@ func getState(evnts ...events.IEventsDB) *state.State { } else { e = evnts[0] } - s, err := state.NewState(0, db.NewMemDB(), e, 1, 1, 0) + s, err := state.NewState(0, db.NewMemDB(), e, 1, 1, 0) // todo: Use NewStateV3 if err != nil { panic(err) } diff --git a/coreV2/transaction/edit_coin_owner_test.go b/coreV2/transaction/edit_coin_owner_test.go index 5a696c1cf..e0646eff4 100644 --- a/coreV2/transaction/edit_coin_owner_test.go +++ b/coreV2/transaction/edit_coin_owner_test.go @@ -19,7 +19,7 @@ import ( func TestEditOwnerTx(t *testing.T) { t.Parallel() - cState, err := state.NewState(0, db.NewMemDB(), nil, 1, 1, 0) + cState, err := state.NewStateV3(0, db.NewMemDB(), nil, 1, 1, 0) if err != nil { t.Fatalf("Cannot load state. Error %s", err) } @@ -78,7 +78,7 @@ func TestEditOwnerTx(t *testing.T) { func TestEditOwnerTxWithWrongOwner(t *testing.T) { t.Parallel() - cState, err := state.NewState(0, db.NewMemDB(), nil, 1, 1, 0) + cState, err := state.NewStateV3(0, db.NewMemDB(), nil, 1, 1, 0) if err != nil { t.Fatalf("Cannot load state. Error %s", err) } @@ -114,7 +114,7 @@ func TestEditOwnerTxWithWrongOwner(t *testing.T) { func TestEditOwnerTxWithWrongSymbol(t *testing.T) { t.Parallel() - cState, err := state.NewState(0, db.NewMemDB(), nil, 1, 1, 0) + cState, err := state.NewStateV3(0, db.NewMemDB(), nil, 1, 1, 0) if err != nil { t.Fatalf("Cannot load state. Error %s", err) } @@ -151,7 +151,7 @@ func TestEditOwnerTxWithWrongSymbol(t *testing.T) { func TestEditCOwnerTxWithInsufficientFunds(t *testing.T) { t.Parallel() - cState, err := state.NewState(0, db.NewMemDB(), nil, 1, 1, 0) + cState, err := state.NewStateV3(0, db.NewMemDB(), nil, 1, 1, 0) if err != nil { t.Fatalf("Cannot load state. Error %s", err) } diff --git a/coreV2/transaction/set_halt_block_test.go b/coreV2/transaction/set_halt_block_test.go index 0ab714619..f1d7db0be 100644 --- a/coreV2/transaction/set_halt_block_test.go +++ b/coreV2/transaction/set_halt_block_test.go @@ -18,7 +18,7 @@ import ( func TestSetHaltBlockTx(t *testing.T) { t.Parallel() - cState, err := state.NewState(0, db.NewMemDB(), nil, 1, 1, 500000) + cState, err := state.NewStateV3(0, db.NewMemDB(), nil, 1, 1, 500000) if err != nil { t.Fatalf("Cannot load state. Error %s", err) } @@ -100,7 +100,7 @@ func TestSetHaltBlockTx(t *testing.T) { func TestSetHaltBlockTxWithWrongHeight(t *testing.T) { t.Parallel() currentHeight := uint64(5) - cState, err := state.NewState(0, db.NewMemDB(), nil, 1, 1, currentHeight) + cState, err := state.NewStateV3(0, db.NewMemDB(), nil, 1, 1, currentHeight) if err != nil { t.Fatalf("Cannot load state. Error %s", err) } @@ -166,7 +166,7 @@ func TestSetHaltBlockTxWithWrongHeight(t *testing.T) { func TestSetHaltBlockTxWithWrongOwnership(t *testing.T) { t.Parallel() currentHeight := uint64(5) - cState, err := state.NewState(0, db.NewMemDB(), nil, 1, 1, currentHeight) + cState, err := state.NewStateV3(0, db.NewMemDB(), nil, 1, 1, currentHeight) if err != nil { t.Fatalf("Cannot load state. Error %s", err) } @@ -232,7 +232,7 @@ func TestSetHaltBlockTxWithWrongOwnership(t *testing.T) { func TestSetHaltBlockTxToNonExistCandidate(t *testing.T) { t.Parallel() - cState, err := state.NewState(0, db.NewMemDB(), nil, 1, 1, 500000) + cState, err := state.NewStateV3(0, db.NewMemDB(), nil, 1, 1, 500000) if err != nil { t.Fatalf("Cannot load state. Error %s", err) } @@ -292,7 +292,7 @@ func TestSetHaltBlockTxToNonExistCandidate(t *testing.T) { func TestSetHaltBlockTxToInsufficientFunds(t *testing.T) { t.Parallel() - cState, err := state.NewState(0, db.NewMemDB(), nil, 1, 1, 500000) + cState, err := state.NewStateV3(0, db.NewMemDB(), nil, 1, 1, 500000) if err != nil { t.Fatalf("Cannot load state. Error %s", err) } @@ -351,7 +351,7 @@ func TestSetHaltBlockTxToInsufficientFunds(t *testing.T) { func TestSetHaltBlockTxToGasCoinReserveUnderflow(t *testing.T) { t.Parallel() - cState, err := state.NewState(0, db.NewMemDB(), nil, 1, 1, 500000) + cState, err := state.NewStateV3(0, db.NewMemDB(), nil, 1, 1, 500000) if err != nil { t.Fatalf("Cannot load state. Error %s", err) } @@ -414,7 +414,7 @@ func TestSetHaltBlockTxToGasCoinReserveUnderflow(t *testing.T) { func TestSetHaltBlockTxToAlreadyExistenHalt(t *testing.T) { t.Parallel() - cState, err := state.NewState(0, db.NewMemDB(), nil, 1, 1, 500000) + cState, err := state.NewStateV3(0, db.NewMemDB(), nil, 1, 1, 500000) if err != nil { t.Fatalf("Cannot load state. Error %s", err) } From 1edb55f8ee86008918dd3cc06a9e7ad76d0056d2 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 3 Jun 2022 03:20:17 +0300 Subject: [PATCH 29/48] update old tests --- coreV2/transaction/buy_coin_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/coreV2/transaction/buy_coin_test.go b/coreV2/transaction/buy_coin_test.go index 53c42ff28..f5e74d70b 100644 --- a/coreV2/transaction/buy_coin_test.go +++ b/coreV2/transaction/buy_coin_test.go @@ -107,6 +107,10 @@ func getTestCoinSymbol() types.CoinSymbol { return coin } +func init() { + rand.Seed(1) +} + func createTestCoin(stateDB *state.State) types.CoinID { volume := helpers.BipToPip(big.NewInt(100000)) reserve := helpers.BipToPip(big.NewInt(100000)) From b6486580cb33794d4b442e6cf8a48e6590bdcbe8 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 3 Jun 2022 13:06:20 +0300 Subject: [PATCH 30/48] refactor for ChainTestnet and filter for invalidIDCandidate --- coreV2/minter/blockchain.go | 37 ++++++++++----------------- coreV2/state/candidates/candidates.go | 7 ++++- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/coreV2/minter/blockchain.go b/coreV2/minter/blockchain.go index e70b12032..8ca7ab2c3 100644 --- a/coreV2/minter/blockchain.go +++ b/coreV2/minter/blockchain.go @@ -472,31 +472,20 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes. var moreRewards = big.NewInt(0) if height%blockchain.updateStakesAndPayRewardsPeriod == 0 { PayRewards := blockchain.stateDeliver.Validators.PayRewardsV3 - if types.CurrentChainID == types.ChainTestnet { - if h := blockchain.appDB.GetVersionHeight(V340); h > 0 && height > h { - PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix2 - } else if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h { - PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix - } else if h := blockchain.appDB.GetVersionHeight(V320); h > 0 && height > h { - PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix - } else if h := blockchain.appDB.GetVersionHeight(V310); h > 0 && height > h { - PayRewards = blockchain.stateDeliver.Validators.PayRewardsV4 - } - } else { - if h := blockchain.appDB.GetVersionHeight(V340); h > 0 && height > h { - PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix2 - } else if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h { - if height < h+blockchain.updateStakesAndPayRewardsPeriod { - excess := blockchain.stateDeliver.Candidates.FixStakesAfter10509400() - blockchain.appDB.SetEmission(big.NewInt(0).Sub(blockchain.appDB.Emission(), excess)) - log.Println("fixEmission", blockchain.appDB.Emission()) - } - PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix - } else if h := blockchain.appDB.GetVersionHeight(V320); h > 0 && height > h { - PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Bug - } else if h := blockchain.appDB.GetVersionHeight(V310); h > 0 && height > h { - PayRewards = blockchain.stateDeliver.Validators.PayRewardsV4 + + if h := blockchain.appDB.GetVersionHeight(V340); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix2 + } else if h := blockchain.appDB.GetVersionHeight(V330); h > 0 && height > h { + if height < h+blockchain.updateStakesAndPayRewardsPeriod && types.CurrentChainID == types.ChainMainnet { + excess := blockchain.stateDeliver.Candidates.FixStakesAfter10509400() + blockchain.appDB.SetEmission(big.NewInt(0).Sub(blockchain.appDB.Emission(), excess)) + log.Println("fixEmission", blockchain.appDB.Emission()) } + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Fix + } else if h := blockchain.appDB.GetVersionHeight(V320); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5Bug + } else if h := blockchain.appDB.GetVersionHeight(V310); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV4 } moreRewards = PayRewards(heightIsMaxIfIssueIsOverOrNotDynamic, int64(blockchain.updateStakesAndPayRewardsPeriod)) diff --git a/coreV2/state/candidates/candidates.go b/coreV2/state/candidates/candidates.go index e6fa517fb..f3cfa1119 100644 --- a/coreV2/state/candidates/candidates.go +++ b/coreV2/state/candidates/candidates.go @@ -1155,6 +1155,9 @@ func (c *Candidates) DeletedCandidates() (result []*deletedID) { c.loadDeletedCandidates() for _, c := range c.deletedCandidates { + if c.PubKey.String() == invalidIDCandidate { + continue + } result = append(result, &deletedID{ ID: c.ID, PubKey: c.PubKey, @@ -1399,6 +1402,8 @@ func (c *Candidates) ID(pubKey types.Pubkey) uint32 { return c.id(pubKey) } +const invalidIDCandidate = "Mp0e11415ef24919557dcea4890d9e8aa26dc31ef8e77c6343114e1180ebeccde3" + // PubKey returns a public key of candidate by it's ID func (c *Candidates) PubKey(id uint32) types.Pubkey { c.lock.RLock() @@ -1411,7 +1416,7 @@ func (c *Candidates) PubKey(id uint32) types.Pubkey { c.loadDeletedCandidates() for pubkey, d := range c.deletedCandidates { - if d.ID == id { // todo: FIXME + if d.ID == id && d.PubKey.String() != invalidIDCandidate { return pubkey } } From 9901403eeaad0e0c6f19857b7c21a2562075f8c5 Mon Sep 17 00:00:00 2001 From: klim0v Date: Wed, 8 Jun 2022 02:26:26 +0300 Subject: [PATCH 31/48] backward compatibility --- coreV2/state/validators/validators.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/coreV2/state/validators/validators.go b/coreV2/state/validators/validators.go index 6fd1b3a7a..299a42db8 100644 --- a/coreV2/state/validators/validators.go +++ b/coreV2/state/validators/validators.go @@ -727,7 +727,12 @@ func (v *Validators) PayRewardsV5Fix(height uint64, period int64) (moreRewards * calcRewards.Sub(calcRewards, taxDAO) calcRewards.Sub(calcRewards, taxDEV) - //calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(developers.Commission+dao.Commission))), big.NewInt(100))) + + { + // backward compatibility + calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(developers.Commission+dao.Commission))), big.NewInt(100))) + } + calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100))) diffDAO := big.NewInt(0).Sub(taxDAOx3, taxDAO) From 41fd2212bd3c7e713f749b8ca9b7cf53c32f93c9 Mon Sep 17 00:00:00 2001 From: klim0v Date: Mon, 13 Jun 2022 03:39:01 +0800 Subject: [PATCH 32/48] remove account coins mutex --- coreV2/state/accounts/accounts.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/coreV2/state/accounts/accounts.go b/coreV2/state/accounts/accounts.go index 78e7ccac5..3f31fc646 100644 --- a/coreV2/state/accounts/accounts.go +++ b/coreV2/state/accounts/accounts.go @@ -382,12 +382,8 @@ func (a *Accounts) GetLockStakeUntilBlock(address types.Address) uint64 { func (a *Accounts) GetBalances(address types.Address) []Balance { account := a.getOrNew(address) - account.lock.RLock() - coins := account.coins - account.lock.RUnlock() - - balances := make([]Balance, len(coins)) - for key, id := range coins { + balances := make([]Balance, len(account.coins)) + for key, id := range account.coins { balances[key] = Balance{ Coin: *a.bus.Coins().GetCoin(id), Value: a.GetBalance(address, id), From e23580e5020222e26748eb6c33d8a12baec08c42 Mon Sep 17 00:00:00 2001 From: klim0v Date: Mon, 13 Jun 2022 15:35:05 +0800 Subject: [PATCH 33/48] remove account coins mutex --- coreV2/state/accounts/accounts.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/coreV2/state/accounts/accounts.go b/coreV2/state/accounts/accounts.go index 3f31fc646..fd9dfdaf4 100644 --- a/coreV2/state/accounts/accounts.go +++ b/coreV2/state/accounts/accounts.go @@ -382,12 +382,12 @@ func (a *Accounts) GetLockStakeUntilBlock(address types.Address) uint64 { func (a *Accounts) GetBalances(address types.Address) []Balance { account := a.getOrNew(address) - balances := make([]Balance, len(account.coins)) - for key, id := range account.coins { - balances[key] = Balance{ + balances := make([]Balance, 0, len(account.coins)) + for _, id := range account.coins { + balances = append(balances, Balance{ Coin: *a.bus.Coins().GetCoin(id), Value: a.GetBalance(address, id), - } + }) } return balances From acd364ed25464bc2b597f5f906305d8cd743a1b7 Mon Sep 17 00:00:00 2001 From: klim0v Date: Wed, 6 Jul 2022 01:28:08 +0800 Subject: [PATCH 34/48] fix rwmu --- coreV2/state/swap/swapV2.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coreV2/state/swap/swapV2.go b/coreV2/state/swap/swapV2.go index b047021dd..262aec7ff 100644 --- a/coreV2/state/swap/swapV2.go +++ b/coreV2/state/swap/swapV2.go @@ -429,8 +429,8 @@ func (s *SwapV2) Commit(db *iavl.MutableTree, version int64) error { } s.muNextOrdersID.Unlock() - s.muPairs.RLock() - defer s.muPairs.RUnlock() + s.muPairs.Lock() + defer s.muPairs.Unlock() for _, key := range s.getOrderedDirtyPairs() { pair, _ := s.pair(key) From 03b5fd582883d459953efd669860fc7ee54ff0e3 Mon Sep 17 00:00:00 2001 From: klim0v Date: Wed, 6 Jul 2022 01:38:54 +0800 Subject: [PATCH 35/48] fix rwmu --- coreV2/state/swap/swapV2.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/coreV2/state/swap/swapV2.go b/coreV2/state/swap/swapV2.go index 262aec7ff..e1807b274 100644 --- a/coreV2/state/swap/swapV2.go +++ b/coreV2/state/swap/swapV2.go @@ -26,8 +26,10 @@ type trader interface { } type SwapV2 struct { - muPairs sync.RWMutex - pairs map[PairKey]*PairV2 + muPairs sync.RWMutex + pairs map[PairKey]*PairV2 + + muDirties sync.RWMutex dirties map[PairKey]struct{} dirtiesOrders map[PairKey]struct{} @@ -429,8 +431,11 @@ func (s *SwapV2) Commit(db *iavl.MutableTree, version int64) error { } s.muNextOrdersID.Unlock() - s.muPairs.Lock() - defer s.muPairs.Unlock() + s.muPairs.RLock() + defer s.muPairs.RUnlock() + + s.muDirties.Lock() + defer s.muDirties.Unlock() for _, key := range s.getOrderedDirtyPairs() { pair, _ := s.pair(key) @@ -715,15 +720,15 @@ func (s *SwapV2) ReturnPair(coin0, coin1 types.CoinID) *PairV2 { func (s *SwapV2) markDirty(key PairKey) func() { return func() { - s.muPairs.Lock() - defer s.muPairs.Unlock() + s.muDirties.Lock() + defer s.muDirties.Unlock() s.dirties[key] = struct{}{} } } func (s *SwapV2) markDirtyOrders(key PairKey) func() { return func() { - s.muPairs.Lock() - defer s.muPairs.Unlock() + s.muDirties.Lock() + defer s.muDirties.Unlock() s.dirtiesOrders[key] = struct{}{} } } From 2f67886f257c26632131c3cd8af8e4bf462b422e Mon Sep 17 00:00:00 2001 From: klim0v Date: Tue, 12 Jul 2022 17:39:42 +0300 Subject: [PATCH 36/48] add todo --- api/v2/service/transaction.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v2/service/transaction.go b/api/v2/service/transaction.go index 611f19cb9..2cc3d2d4d 100644 --- a/api/v2/service/transaction.go +++ b/api/v2/service/transaction.go @@ -23,7 +23,7 @@ func (s *Service) Transaction(ctx context.Context, req *pb.TransactionRequest) ( tx, err := s.client.Tx(ctx, decodeString, false) if err != nil { - return nil, status.Error(codes.FailedPrecondition, err.Error()) + return nil, status.Error(codes.FailedPrecondition, err.Error()) // todo: NotFound } decodedTx, _ := s.decoderTx.DecodeFromBytes(tx.Tx) From 85e3d669722d393ba5f704a71c4cc717e15cfd62 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 23 Jul 2022 14:48:43 +0300 Subject: [PATCH 37/48] fix rw mutex --- api/v2/v2.go | 15 ++++++++------- coreV2/state/accounts/accounts.go | 24 +++++++++++------------- coreV2/state/accounts/model.go | 12 +++++------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/api/v2/v2.go b/api/v2/v2.go index 7d70c4a7f..93bba42dc 100644 --- a/api/v2/v2.go +++ b/api/v2/v2.go @@ -4,6 +4,14 @@ import ( "context" "encoding/json" "fmt" + "io" + "mime" + "net" + "net/http" + "strconv" + "strings" + "time" + "github.com/MinterTeam/minter-go-node/api/v2/service" gw "github.com/MinterTeam/node-grpc-gateway/api_pb" "github.com/MinterTeam/node-grpc-gateway/docs" @@ -25,13 +33,6 @@ import ( "google.golang.org/grpc/status" "google.golang.org/protobuf/encoding/protojson" _struct "google.golang.org/protobuf/types/known/structpb" - "io" - "mime" - "net" - "net/http" - "strconv" - "strings" - "time" ) // Run initialises gRPC and API v2 interfaces diff --git a/coreV2/state/accounts/accounts.go b/coreV2/state/accounts/accounts.go index fd9dfdaf4..195661190 100644 --- a/coreV2/state/accounts/accounts.go +++ b/coreV2/state/accounts/accounts.go @@ -3,6 +3,9 @@ package accounts import ( "bytes" "fmt" + "math/big" + "sort" + "sync" "sync/atomic" "github.com/MinterTeam/minter-go-node/coreV2/state/bus" @@ -10,10 +13,6 @@ import ( "github.com/MinterTeam/minter-go-node/coreV2/types" "github.com/MinterTeam/minter-go-node/rlp" "github.com/cosmos/iavl" - - "math/big" - "sort" - "sync" ) const mainPrefix = byte('a') @@ -40,7 +39,8 @@ type Accounts struct { db atomic.Value bus *bus.Bus - lock sync.RWMutex + lock sync.RWMutex + lockDirties sync.RWMutex } type Balance struct { @@ -75,9 +75,9 @@ func (a *Accounts) Commit(db *iavl.MutableTree, version int64) error { accounts := a.getOrderedDirtyAccounts() for _, address := range accounts { account := a.getFromMap(address) - a.lock.Lock() + a.lockDirties.Lock() delete(a.dirty, address) - a.lock.Unlock() + a.lockDirties.Unlock() // save info (nonce and multisig data) if a.IsNewOrDirty(account) { @@ -166,12 +166,12 @@ func (a *Accounts) IsNewOrDirty(account *Model) bool { } func (a *Accounts) getOrderedDirtyAccounts() []types.Address { - a.lock.RLock() + a.lockDirties.RLock() keys := make([]types.Address, 0, len(a.dirty)) for k := range a.dirty { keys = append(keys, k) } - a.lock.RUnlock() + a.lockDirties.RUnlock() sort.SliceStable(keys, func(i, j int) bool { return bytes.Compare(keys[i].Bytes(), keys[j].Bytes()) == 1 @@ -373,8 +373,6 @@ func (a *Accounts) SetLockStakeUntilBlock(address types.Address, h uint64) { func (a *Accounts) GetLockStakeUntilBlock(address types.Address) uint64 { account := a.getOrNew(address) - account.lock.RLock() - defer account.lock.RUnlock() return account.getLockStakeUntilBlock() } @@ -394,8 +392,8 @@ func (a *Accounts) GetBalances(address types.Address) []Balance { } func (a *Accounts) markDirty(addr types.Address) { - a.lock.Lock() - defer a.lock.Unlock() + a.lockDirties.Lock() + defer a.lockDirties.Unlock() a.dirty[addr] = struct{}{} } diff --git a/coreV2/state/accounts/model.go b/coreV2/state/accounts/model.go index 3b23e8acd..b1e00658f 100644 --- a/coreV2/state/accounts/model.go +++ b/coreV2/state/accounts/model.go @@ -1,12 +1,13 @@ package accounts import ( - "github.com/MinterTeam/minter-go-node/coreV2/types" - "github.com/MinterTeam/minter-go-node/crypto" - "github.com/MinterTeam/minter-go-node/rlp" "math/big" "sort" "sync" + + "github.com/MinterTeam/minter-go-node/coreV2/types" + "github.com/MinterTeam/minter-go-node/crypto" + "github.com/MinterTeam/minter-go-node/rlp" ) type Model struct { @@ -120,16 +121,13 @@ func (model *Model) setBalance(coin types.CoinID, amount *big.Int) { var newCoins []types.CoinID - model.lock.RLock() + model.lock.Lock() for _, c := range model.coins { if coin == c { continue } newCoins = append(newCoins, c) } - model.lock.RUnlock() - - model.lock.Lock() model.hasDirtyCoins = true model.coins = newCoins model.balances[coin] = amount From 8f4cbf3eaf0113f59dfb88b380e9161e9a8c2310 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 23 Jul 2022 13:48:56 +0300 Subject: [PATCH 38/48] add endpoint changeSwapPoolAmountsForPrice --- api/v2/service/custom.go | 33 +++++++++++++++++++++++++++++++++ api/v2/v2.go | 2 ++ go.mod | 10 ++++++++++ go.sum | 12 ++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 api/v2/service/custom.go diff --git a/api/v2/service/custom.go b/api/v2/service/custom.go new file mode 100644 index 000000000..ed18a7923 --- /dev/null +++ b/api/v2/service/custom.go @@ -0,0 +1,33 @@ +package service + +import ( + "log" + "math/big" + "net/http" + "strconv" + + "github.com/MinterTeam/minter-go-node/coreV2/types" + "github.com/gin-gonic/gin" +) + +func (s *Service) customExample(c *gin.Context) { + coin0S := c.Param("coin0") + coin1S := c.Param("coin1") + priceS := c.Param("price") + coin0I, _ := strconv.Atoi(coin0S) + coin1I, _ := strconv.Atoi(coin1S) + priceF, _ := strconv.ParseFloat(priceS, 10) + log.Println(coin0I, coin1I, priceF) + amount0, amount1 := s.blockchain.CurrentState().Swap().GetSwapper(types.CoinID(coin1I), types.CoinID(coin0I)).CalculateAddAmountsForPrice(big.NewFloat(1 / priceF)) + c.JSON(200, gin.H{ + "amount0": amount0, + "amount1": amount1, + }) +} + +// CustomHandlers return custom http methods +func (s *Service) CustomHandlers() http.Handler { + r := gin.Default() + r.GET("/swap_pool/:coin0/:coin1/:price", s.customExample) + return r +} diff --git a/api/v2/v2.go b/api/v2/v2.go index 93bba42dc..be9587317 100644 --- a/api/v2/v2.go +++ b/api/v2/v2.go @@ -117,6 +117,8 @@ func Run(srv *service.Service, addrGRPC, addrAPI string, logger log.Logger) erro http.StripPrefix("/v2", handlers.CompressHandler(allowCORS(wsproxy.WebsocketProxy(gwmux)))).ServeHTTP(writer, request) }) + mux.Handle("/v2/custom/", http.StripPrefix("/v2/custom", srv.CustomHandlers())) + group.Go(func() error { return http.ListenAndServe(addrAPI, mux) }) diff --git a/go.mod b/go.mod index 9fbfb81a4..5c1af7f17 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/c-bata/go-prompt v0.2.5 github.com/cosmos/cosmos-sdk v0.44.5 github.com/cosmos/iavl v0.17.3 + github.com/gin-gonic/gin v1.6.3 github.com/go-kit/kit v0.12.0 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.2 @@ -53,8 +54,12 @@ require ( github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/gdamore/encoding v0.0.0-20151215212835-b23993cbb635 // indirect github.com/gdamore/tcell v1.1.0 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-kit/log v0.2.0 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect + github.com/go-playground/locales v0.13.0 // indirect + github.com/go-playground/universal-translator v0.17.0 // indirect + github.com/go-playground/validator/v10 v10.2.0 // indirect github.com/golang/snappy v0.0.3 // indirect github.com/google/btree v1.0.0 // indirect github.com/google/orderedcode v0.0.1 // indirect @@ -64,6 +69,8 @@ require ( github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/jmhodges/levigo v1.0.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.10.4 // indirect github.com/libp2p/go-buffer-pool v0.0.2 // indirect github.com/lucasb-eyer/go-colorful v0.0.0-20180709185858-c7842319cf3a // indirect @@ -77,6 +84,8 @@ require ( github.com/minio/highwayhash v1.0.2 // indirect github.com/mitchellh/go-wordwrap v1.0.0 // indirect github.com/mitchellh/mapstructure v1.4.3 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml v1.9.4 // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pkg/term v1.1.0 // indirect @@ -95,6 +104,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.2.0 // indirect github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect + github.com/ugorji/go/codec v1.1.7 // indirect go.etcd.io/bbolt v1.3.6 // indirect golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect golang.org/x/text v0.3.7 // indirect diff --git a/go.sum b/go.sum index c1e17a09a..f2328a6f0 100644 --- a/go.sum +++ b/go.sum @@ -323,7 +323,9 @@ github.com/gdamore/encoding v0.0.0-20151215212835-b23993cbb635/go.mod h1:yrQYJKK github.com/gdamore/tcell v1.1.0 h1:RbQgl7jukmdqROeNcKps7R2YfDCQbWkOd1BwdXrxfr4= github.com/gdamore/tcell v1.1.0/go.mod h1:tqyG50u7+Ctv1w5VX67kLzKcj9YXR/JSBZQq/+mLl1A= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -342,9 +344,13 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA= github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= +github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= @@ -573,6 +579,7 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= @@ -606,6 +613,7 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= @@ -684,9 +692,11 @@ github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGg github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= @@ -975,8 +985,10 @@ github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9 github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/tyler-smith/go-bip39 v1.0.2/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY= From 889edd5f2fc277f0c6f564a574a10844b6334d7f Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 23 Jul 2022 14:55:23 +0300 Subject: [PATCH 39/48] mark v340 as beta --- coreV2/minter/blockchain.go | 15 ++++++++------- version/version.go | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/coreV2/minter/blockchain.go b/coreV2/minter/blockchain.go index 8ca7ab2c3..804057fda 100644 --- a/coreV2/minter/blockchain.go +++ b/coreV2/minter/blockchain.go @@ -3,12 +3,6 @@ package minter import ( "context" "fmt" - "github.com/MinterTeam/minter-go-node/coreV2/state/candidates" - "github.com/MinterTeam/minter-go-node/helpers" - "github.com/cosmos/cosmos-sdk/snapshots" - snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" - "github.com/cosmos/cosmos-sdk/types/errors" - tmlog "github.com/tendermint/tendermint/libs/log" "log" "math" "math/big" @@ -17,6 +11,13 @@ import ( "sync/atomic" "time" + "github.com/MinterTeam/minter-go-node/coreV2/state/candidates" + "github.com/MinterTeam/minter-go-node/helpers" + "github.com/cosmos/cosmos-sdk/snapshots" + snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" + "github.com/cosmos/cosmos-sdk/types/errors" + tmlog "github.com/tendermint/tendermint/libs/log" + l "github.com/MinterTeam/minter-go-node/log" "github.com/MinterTeam/minter-go-node/cmd/utils" @@ -160,7 +161,7 @@ func NewMinterBlockchain(storages *utils.Storage, cfg *config.Config, ctx contex V310: {}, // hotfix V320: {}, V330: {}, - V340: {}, + //V340: {}, // TODO: Only for release version }, executor: GetExecutor(V3), } diff --git a/version/version.go b/version/version.go index cd04248af..843067519 100755 --- a/version/version.go +++ b/version/version.go @@ -7,7 +7,7 @@ const ( var ( // Version must be a string because scripts like dist.sh read this file. - Version = "3.4.0" + Version = "3.4.0-beta" // GitCommit is the current HEAD set using ldflags. GitCommit string From f976d8035d656c3995ea540e0d151e4ba7bf0783 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 23 Jul 2022 14:53:12 +0300 Subject: [PATCH 40/48] fix Transaction endpoint response 404 --- api/v2/service/transaction.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v2/service/transaction.go b/api/v2/service/transaction.go index 2cc3d2d4d..20a65fac3 100644 --- a/api/v2/service/transaction.go +++ b/api/v2/service/transaction.go @@ -23,7 +23,7 @@ func (s *Service) Transaction(ctx context.Context, req *pb.TransactionRequest) ( tx, err := s.client.Tx(ctx, decodeString, false) if err != nil { - return nil, status.Error(codes.FailedPrecondition, err.Error()) // todo: NotFound + return nil, status.Error(codes.NotFound, err.Error()) } decodedTx, _ := s.decoderTx.DecodeFromBytes(tx.Tx) From 3a76eda04ea7de91d325539b97bf5a2f074574cd Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 23 Jul 2022 15:23:22 +0300 Subject: [PATCH 41/48] update docs --- CHANGELOG.md | 1 + api/v2/service/custom.go | 43 +++++++++++++++++++++++++++--------- api/v2/v2.go | 2 +- coreV2/state/swap/orderV2.go | 4 ++-- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24e330b17..0e2a1ab94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Fixed +- API Balance deadlock - Calculation of x3 rewards ## [v3.3.0](https://github.com/MinterTeam/minter-go-node/tree/v3.3.0) diff --git a/api/v2/service/custom.go b/api/v2/service/custom.go index ed18a7923..6e1e9ce01 100644 --- a/api/v2/service/custom.go +++ b/api/v2/service/custom.go @@ -1,7 +1,6 @@ package service import ( - "log" "math/big" "net/http" "strconv" @@ -10,24 +9,48 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Service) customExample(c *gin.Context) { +func (s *Service) changeAmountsForPrice(c *gin.Context) { coin0S := c.Param("coin0") coin1S := c.Param("coin1") priceS := c.Param("price") - coin0I, _ := strconv.Atoi(coin0S) - coin1I, _ := strconv.Atoi(coin1S) - priceF, _ := strconv.ParseFloat(priceS, 10) - log.Println(coin0I, coin1I, priceF) - amount0, amount1 := s.blockchain.CurrentState().Swap().GetSwapper(types.CoinID(coin1I), types.CoinID(coin0I)).CalculateAddAmountsForPrice(big.NewFloat(1 / priceF)) + coin0I, err := strconv.Atoi(coin0S) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": map[string]string{ + "message": err.Error(), + }, + }) + return + } + coin1I, err := strconv.Atoi(coin1S) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": map[string]string{ + "message": err.Error(), + }, + }) + return + } + priceF, err := strconv.ParseFloat(priceS, 10) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": map[string]string{ + "message": err.Error(), + }, + }) + return + } + amount0, amount1 := s.blockchain.CurrentState().Swap().GetSwapper(types.CoinID(coin0I), types.CoinID(coin1I)).CalculateAddAmountsForPrice(big.NewFloat(1 / priceF)) c.JSON(200, gin.H{ - "amount0": amount0, - "amount1": amount1, + "amount0In": amount0, + "amount1Out": amount1, + // todo: reverse price if amounts nil }) } // CustomHandlers return custom http methods func (s *Service) CustomHandlers() http.Handler { r := gin.Default() - r.GET("/swap_pool/:coin0/:coin1/:price", s.customExample) + r.GET("/change_amounts_for_price/:coin0/:coin1/:price", s.changeAmountsForPrice) return r } diff --git a/api/v2/v2.go b/api/v2/v2.go index be9587317..83ef1b96b 100644 --- a/api/v2/v2.go +++ b/api/v2/v2.go @@ -117,7 +117,7 @@ func Run(srv *service.Service, addrGRPC, addrAPI string, logger log.Logger) erro http.StripPrefix("/v2", handlers.CompressHandler(allowCORS(wsproxy.WebsocketProxy(gwmux)))).ServeHTTP(writer, request) }) - mux.Handle("/v2/custom/", http.StripPrefix("/v2/custom", srv.CustomHandlers())) + mux.Handle("/v2/customs/", http.StripPrefix("/v2/customs", srv.CustomHandlers())) group.Go(func() error { return http.ListenAndServe(addrAPI, mux) diff --git a/coreV2/state/swap/orderV2.go b/coreV2/state/swap/orderV2.go index 5a351f728..db63a936e 100644 --- a/coreV2/state/swap/orderV2.go +++ b/coreV2/state/swap/orderV2.go @@ -3,13 +3,14 @@ package swap import ( "encoding/binary" "fmt" - "github.com/MinterTeam/minter-go-node/coreV2/events" "log" "math" "math/big" "sort" "sync" + "github.com/MinterTeam/minter-go-node/coreV2/events" + "github.com/MinterTeam/minter-go-node/coreV2/types" "github.com/MinterTeam/minter-go-node/rlp" "github.com/cosmos/iavl" @@ -323,7 +324,6 @@ func (p *PairV2) calculateBuyForSellWithOrders(amount0In *big.Int) (amountOut *b func (p *PairV2) CalculateAddAmountsForPrice(price *big.Float) (amount0In, amount1Out *big.Int) { if price.Cmp(p.Price()) == 1 { - fmt.Println("price cur and first ord", price, p.Price()) return nil, nil } return p.calculateAddAmountsForPrice(price) From 8b0e9a515c07778962a132cc91d85ee5077ad0fd Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 23 Jul 2022 15:54:23 +0300 Subject: [PATCH 42/48] update docs^ add endpoint LimitOrdersByOwner --- CHANGELOG.md | 2 +- api/v2/service/swap_pool.go | 51 +++++++++++++++++++++++++++++++++++-- coreV2/state/swap/swap.go | 8 +++++- coreV2/state/swap/swapV2.go | 38 ++++++++++++++++++++++++++- go.mod | 14 +++++----- go.sum | 39 +++++++++------------------- 6 files changed, 113 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e2a1ab94..1ef971a9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ ### Added -- API method: `waitlist_all` +- API methods: `waitlist_all`, `limit_orders_by_owner` - Indexed tags to search for transactions by order ### Fixed diff --git a/api/v2/service/swap_pool.go b/api/v2/service/swap_pool.go index c82c9300a..b42caa641 100644 --- a/api/v2/service/swap_pool.go +++ b/api/v2/service/swap_pool.go @@ -4,11 +4,12 @@ import ( "context" "encoding/hex" "fmt" - "github.com/MinterTeam/minter-go-node/coreV2/state/swap" - "github.com/MinterTeam/minter-go-node/helpers" "sort" "strings" + "github.com/MinterTeam/minter-go-node/coreV2/state/swap" + "github.com/MinterTeam/minter-go-node/helpers" + "github.com/MinterTeam/minter-go-node/coreV2/transaction" "github.com/MinterTeam/minter-go-node/coreV2/types" pb "github.com/MinterTeam/node-grpc-gateway/api_pb" @@ -168,6 +169,52 @@ func (s *Service) LimitOrders(ctx context.Context, req *pb.LimitOrdersRequest) ( return resp, nil } +func (s *Service) LimitOrdersByOwner(ctx context.Context, req *pb.LimitOrdersByOwnerRequest) (*pb.LimitOrdersResponse, error) { + cState, err := s.blockchain.GetStateForHeight(req.Height) + if err != nil { + return nil, status.Error(codes.NotFound, err.Error()) + } + + if !strings.HasPrefix(strings.Title(req.Address), "Mx") { + return nil, status.Error(codes.InvalidArgument, "invalid address") + } + + decodeString, err := hex.DecodeString(req.Address[2:]) + if err != nil { + return nil, status.Error(codes.InvalidArgument, "invalid address") + } + + address := types.BytesToAddress(decodeString) + + resp := &pb.LimitOrdersResponse{Orders: make([]*pb.LimitOrderResponse, 0, 0)} + + orders := cState.Swap().GetOrdersByOwner(ctx, address) + + for _, order := range orders { + if order.IsBuy { + order = order.Reverse() + } + + resp.Orders = append(resp.Orders, &pb.LimitOrderResponse{ + Id: uint64(order.ID()), + CoinSell: &pb.Coin{ + Id: uint64(order.Coin1), + Symbol: cState.Coins().GetCoin(order.Coin1).GetFullSymbol(), + }, + CoinBuy: &pb.Coin{ + Id: uint64(order.Coin0), + Symbol: cState.Coins().GetCoin(order.Coin0).GetFullSymbol(), + }, + WantSell: order.WantSell.String(), + WantBuy: order.WantBuy.String(), + Price: swap.CalcPriceSellRat(order.WantBuy, order.WantSell).FloatString(precision), + Owner: order.Owner.String(), + Height: order.Height, + }) + } + + return resp, nil +} func (s *Service) SwapPool(ctx context.Context, req *pb.SwapPoolRequest) (*pb.SwapPoolResponse, error) { if req.Coin0 == req.Coin1 { diff --git a/coreV2/state/swap/swap.go b/coreV2/state/swap/swap.go index 1d876ee77..3bcb54ff3 100644 --- a/coreV2/state/swap/swap.go +++ b/coreV2/state/swap/swap.go @@ -6,7 +6,6 @@ import ( "encoding/binary" "errors" "fmt" - "github.com/MinterTeam/minter-go-node/coreV2/events" "math" "math/big" "sort" @@ -15,6 +14,8 @@ import ( "sync" "sync/atomic" + "github.com/MinterTeam/minter-go-node/coreV2/events" + "github.com/MinterTeam/minter-go-node/coreV2/state/bus" "github.com/MinterTeam/minter-go-node/coreV2/types" "github.com/MinterTeam/minter-go-node/helpers" @@ -71,6 +72,7 @@ type RSwap interface { GetBestTradeExactIn(ctx context.Context, outId, inId uint64, inAmount *big.Int, maxHops int32) *Trade GetBestTradeExactOut(ctx context.Context, inId, outId uint64, outAmount *big.Int, maxHops int32) *Trade + GetOrdersByOwner(ctx context.Context, address types.Address) []*Limit SwapPools(context.Context) []EditableChecker GetOrder(id uint32) *Limit Export(state *types.AppState) @@ -1299,3 +1301,7 @@ func startingSupply(amount0 *big.Int, amount1 *big.Int) *big.Int { mul := new(big.Int).Mul(amount0, amount1) return new(big.Int).Sqrt(mul) } + +func (s *Swap) GetOrdersByOwner(ctx context.Context, address types.Address) []*Limit { + return nil +} diff --git a/coreV2/state/swap/swapV2.go b/coreV2/state/swap/swapV2.go index e1807b274..720c9e6fd 100644 --- a/coreV2/state/swap/swapV2.go +++ b/coreV2/state/swap/swapV2.go @@ -5,7 +5,6 @@ import ( "context" "encoding/binary" "fmt" - "github.com/MinterTeam/minter-go-node/coreV2/events" "math" "math/big" "sort" @@ -13,6 +12,8 @@ import ( "sync" "sync/atomic" + "github.com/MinterTeam/minter-go-node/coreV2/events" + "github.com/MinterTeam/minter-go-node/coreV2/state/bus" "github.com/MinterTeam/minter-go-node/coreV2/types" "github.com/MinterTeam/minter-go-node/helpers" @@ -172,6 +173,41 @@ func (s *SwapV2) loadPools() { s.loadedPools = true } +func (s *SwapV2) GetOrdersByOwner(ctx context.Context, address types.Address) []*Limit { + var orders []*Limit + s.immutableTree().IterateRange(pathOrder(0), pathOrder(math.MaxUint32), true, func(key []byte, value []byte) bool { + if value == nil { + return false + } + + id := binary.BigEndian.Uint32(key[1:]) + + order := &Limit{ + id: id, + oldSortPrice: new(big.Float).SetPrec(Precision), + mu: new(sync.RWMutex), + } + err := rlp.DecodeBytes(value, order) + if err != nil { + panic(err) + } + + if order.Owner == address { + orders = append(orders, order) + } + + select { + case <-ctx.Done(): + return true + default: + } + + return false + }) + + return orders +} + func (s *SwapV2) ExpireOrders(beforeHeight uint64) { var orders []*Limit s.immutableTree().IterateRange(pathOrder(0), pathOrder(math.MaxUint32), true, func(key []byte, value []byte) bool { diff --git a/go.mod b/go.mod index 5c1af7f17..980e5db64 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module github.com/MinterTeam/minter-go-node -go 1.17 +go 1.18 require ( - github.com/MinterTeam/node-grpc-gateway v1.7.0 + github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220723123624-0e70deb77803 github.com/btcsuite/btcd v0.22.0-beta github.com/c-bata/go-prompt v0.2.5 github.com/cosmos/cosmos-sdk v0.44.5 @@ -15,7 +15,7 @@ require ( github.com/gorilla/handlers v1.5.1 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 - github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 + github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.0 github.com/marcusolsson/tui-go v0.4.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.12.1 @@ -30,8 +30,8 @@ require ( github.com/urfave/cli/v2 v2.0.0 golang.org/x/crypto v0.0.0-20211202192323-5770296d904e golang.org/x/sync v0.0.0-20210220032951-036812b2e83c - golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 - google.golang.org/grpc v1.46.2 + golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f + google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.0 ) @@ -106,9 +106,9 @@ require ( github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect github.com/ugorji/go/codec v1.1.7 // indirect go.etcd.io/bbolt v1.3.6 // indirect - golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect + golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect golang.org/x/text v0.3.7 // indirect - google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect + google.golang.org/genproto v0.0.0-20220722212130-b98a9ff5e252 // indirect gopkg.in/ini.v1 v1.66.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index f2328a6f0..dc0de14df 100644 --- a/go.sum +++ b/go.sum @@ -85,8 +85,8 @@ github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jB github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY= github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= -github.com/MinterTeam/node-grpc-gateway v1.7.0 h1:EN4GsIVh+thloOUKTWJYEeHTkiTx941mG/t6u1xmwiA= -github.com/MinterTeam/node-grpc-gateway v1.7.0/go.mod h1:ABl5Sn4RJobzU07kbQ2xi1yzRTMFYHMpgzixTBaN0zI= +github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220723123624-0e70deb77803 h1:eEBsH5kWjdxr08Mr936kZcHbyHKdJ1LaQ/UAI3T14X4= +github.com/MinterTeam/node-grpc-gateway v1.6.2-0.20220723123624-0e70deb77803/go.mod h1:uRf2jeLkIoY3wKpPVvEiUCOqK7WM8LdH2kk3HuwIx/E= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= @@ -231,7 +231,6 @@ github.com/cosmos/iavl v0.17.3 h1:s2N819a2olOmiauVa0WAhoIJq9EhSXE9HDBAoR9k+8Y= github.com/cosmos/iavl v0.17.3/go.mod h1:prJoErZFABYZGDHka1R6Oay4z9PrNeFFiMKHDAMOi4w= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9QWFanOyI= -github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -371,7 +370,6 @@ github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188/go.mod h1:vXjM/+ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= -github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -427,7 +425,6 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64= @@ -491,8 +488,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 h1:BGNSrTRW4rwfhJiFwvwF4XQ0Y72Jj9YEgxVrtovbD5o= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3/go.mod h1:VHn7KgNsRriXa4mcgtkpR00OXyQY6g67JWMvn+R27A4= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.0 h1:Ghn7copILfeIg0y8sTGRppI1bd8I4l2VN3cob0Xeqwg= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.0/go.mod h1:dnjr4snxnhRSn5GWqJUva2AoMbeaxyAcepvc0Tg8lXk= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= github.com/gtank/merlin v0.1.1 h1:eQ90iG7K9pOhtereWsmyRJ6RAwcP4tHTDBHXNg+u5is= @@ -607,7 +604,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -792,7 +788,6 @@ github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -861,9 +856,7 @@ github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRr github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U= @@ -871,7 +864,6 @@ github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.23.0/go.mod h1:6c7hFfxPOy7TacJc4Fcdi24/J0NKYGzjG8FWRI916Qo= -github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= @@ -985,13 +977,11 @@ github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9 github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/tyler-smith/go-bip39 v1.0.2/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= -github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.0.0 h1:+HU9SCbu8GnEUFtIBfuUNXN39ofWViIEJIp6SURMpCg= github.com/urfave/cli/v2 v2.0.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= @@ -1179,11 +1169,10 @@ golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211208012354-db4efeb81f4b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= -golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1202,7 +1191,6 @@ golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1313,12 +1301,11 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1520,8 +1507,8 @@ google.golang.org/genproto v0.0.0-20211028162531-8db9c33dc351/go.mod h1:5CzLGKJ6 google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd h1:e0TwkXOdbnH/1x5rc5MZ/VYyiZ4v+RdVfrGMqEwT68I= -google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= +google.golang.org/genproto v0.0.0-20220722212130-b98a9ff5e252 h1:G5AjFxR+ibe9Taamo0TdW+iylfBYK10DSkHYdx7PZ9w= +google.golang.org/genproto v0.0.0-20220722212130-b98a9ff5e252/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= @@ -1558,9 +1545,8 @@ google.golang.org/grpc v1.40.1/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9K google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= -google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= -google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ= -google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= +google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= @@ -1587,7 +1573,6 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= From 2932fc62d5be9f10715e77d2735bf5ef95817cea Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 23 Jul 2022 16:21:09 +0300 Subject: [PATCH 43/48] refactor --- api/v2/service/custom.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/v2/service/custom.go b/api/v2/service/custom.go index 6e1e9ce01..e7405f441 100644 --- a/api/v2/service/custom.go +++ b/api/v2/service/custom.go @@ -50,6 +50,7 @@ func (s *Service) changeAmountsForPrice(c *gin.Context) { // CustomHandlers return custom http methods func (s *Service) CustomHandlers() http.Handler { + gin.SetMode(gin.ReleaseMode) r := gin.Default() r.GET("/change_amounts_for_price/:coin0/:coin1/:price", s.changeAmountsForPrice) return r From 87ede6025fd4651a87fae9ede36cb57d024dbc60 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sat, 23 Jul 2022 16:40:21 +0300 Subject: [PATCH 44/48] refactor --- CHANGELOG.md | 1 + api/v2/service/swap_pool.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ef971a9e..9efd753d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - API methods: `waitlist_all`, `limit_orders_by_owner` - Indexed tags to search for transactions by order +- Starting a node without processing new states with tag `--only-api-mode` ### Fixed diff --git a/api/v2/service/swap_pool.go b/api/v2/service/swap_pool.go index b42caa641..7a1ff267f 100644 --- a/api/v2/service/swap_pool.go +++ b/api/v2/service/swap_pool.go @@ -169,12 +169,17 @@ func (s *Service) LimitOrders(ctx context.Context, req *pb.LimitOrdersRequest) ( return resp, nil } + func (s *Service) LimitOrdersByOwner(ctx context.Context, req *pb.LimitOrdersByOwnerRequest) (*pb.LimitOrdersResponse, error) { cState, err := s.blockchain.GetStateForHeight(req.Height) if err != nil { return nil, status.Error(codes.NotFound, err.Error()) } + if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil { + return nil, timeoutStatus.Err() + } + if !strings.HasPrefix(strings.Title(req.Address), "Mx") { return nil, status.Error(codes.InvalidArgument, "invalid address") } @@ -190,6 +195,10 @@ func (s *Service) LimitOrdersByOwner(ctx context.Context, req *pb.LimitOrdersByO orders := cState.Swap().GetOrdersByOwner(ctx, address) + if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil { + return nil, timeoutStatus.Err() + } + for _, order := range orders { if order.IsBuy { order = order.Reverse() From 408e5ac3e02705b15af2fd9626313b4a08727568 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sun, 24 Jul 2022 13:13:59 +0300 Subject: [PATCH 45/48] endpoint GetOrdersAll --- api/v2/service/swap_pool.go | 32 ++++++++++++++++++++++++++++++++ coreV2/state/swap/swap.go | 4 ++++ coreV2/state/swap/swapV2.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/api/v2/service/swap_pool.go b/api/v2/service/swap_pool.go index 7a1ff267f..2d08ff8c3 100644 --- a/api/v2/service/swap_pool.go +++ b/api/v2/service/swap_pool.go @@ -129,7 +129,39 @@ func (s *Service) LimitOrders(ctx context.Context, req *pb.LimitOrdersRequest) ( if capacity > 50 { capacity = 50 } + resp := &pb.LimitOrdersResponse{Orders: make([]*pb.LimitOrderResponse, 0, capacity)} + if capacity == 0 { + orders := cState.Swap().GetOrdersAll(ctx) + if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil { + return nil, timeoutStatus.Err() + } + + for _, order := range orders { + if order.IsBuy { + order = order.Reverse() + } + + resp.Orders = append(resp.Orders, &pb.LimitOrderResponse{ + Id: uint64(order.ID()), + CoinSell: &pb.Coin{ + Id: uint64(order.Coin1), + Symbol: cState.Coins().GetCoin(order.Coin1).GetFullSymbol(), + }, + CoinBuy: &pb.Coin{ + Id: uint64(order.Coin0), + Symbol: cState.Coins().GetCoin(order.Coin0).GetFullSymbol(), + }, + WantSell: order.WantSell.String(), + WantBuy: order.WantBuy.String(), + Price: swap.CalcPriceSellRat(order.WantBuy, order.WantSell).FloatString(precision), + Owner: order.Owner.String(), + Height: order.Height, + }) + } + + return resp, nil + } for _, id := range req.Ids { if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil { diff --git a/coreV2/state/swap/swap.go b/coreV2/state/swap/swap.go index 3bcb54ff3..0677cbc7b 100644 --- a/coreV2/state/swap/swap.go +++ b/coreV2/state/swap/swap.go @@ -73,6 +73,7 @@ type RSwap interface { GetBestTradeExactOut(ctx context.Context, inId, outId uint64, outAmount *big.Int, maxHops int32) *Trade GetOrdersByOwner(ctx context.Context, address types.Address) []*Limit + GetOrdersAll(ctx context.Context) []*Limit SwapPools(context.Context) []EditableChecker GetOrder(id uint32) *Limit Export(state *types.AppState) @@ -1305,3 +1306,6 @@ func startingSupply(amount0 *big.Int, amount1 *big.Int) *big.Int { func (s *Swap) GetOrdersByOwner(ctx context.Context, address types.Address) []*Limit { return nil } +func (s *Swap) GetOrdersAll(ctx context.Context) []*Limit { + return nil +} diff --git a/coreV2/state/swap/swapV2.go b/coreV2/state/swap/swapV2.go index 720c9e6fd..b34c9ce31 100644 --- a/coreV2/state/swap/swapV2.go +++ b/coreV2/state/swap/swapV2.go @@ -173,6 +173,37 @@ func (s *SwapV2) loadPools() { s.loadedPools = true } +func (s *SwapV2) GetOrdersAll(ctx context.Context) []*Limit { + var orders []*Limit + s.immutableTree().IterateRange(pathOrder(0), pathOrder(math.MaxUint32), true, func(key []byte, value []byte) bool { + if value == nil { + return false + } + + id := binary.BigEndian.Uint32(key[1:]) + + order := &Limit{ + id: id, + oldSortPrice: new(big.Float).SetPrec(Precision), + mu: new(sync.RWMutex), + } + err := rlp.DecodeBytes(value, order) + if err != nil { + panic(err) + } + + select { + case <-ctx.Done(): + return true + default: + } + + return false + }) + + return orders +} + func (s *SwapV2) GetOrdersByOwner(ctx context.Context, address types.Address) []*Limit { var orders []*Limit s.immutableTree().IterateRange(pathOrder(0), pathOrder(math.MaxUint32), true, func(key []byte, value []byte) bool { From c26b9dbf79a0c6ae976741d43a823c9b26bb23a5 Mon Sep 17 00:00:00 2001 From: klim0v Date: Sun, 24 Jul 2022 14:51:32 +0300 Subject: [PATCH 46/48] refactor --- api/v2/service/swap_pool.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/v2/service/swap_pool.go b/api/v2/service/swap_pool.go index 2d08ff8c3..bab7b2b04 100644 --- a/api/v2/service/swap_pool.go +++ b/api/v2/service/swap_pool.go @@ -126,8 +126,8 @@ func (s *Service) LimitOrders(ctx context.Context, req *pb.LimitOrdersRequest) ( } capacity := len(req.Ids) - if capacity > 50 { - capacity = 50 + if capacity > 1000 || capacity == 0 { + capacity = 1000 } resp := &pb.LimitOrdersResponse{Orders: make([]*pb.LimitOrderResponse, 0, capacity)} From 3e2218fe26cf69fdbaf075494fe365dbf27389a7 Mon Sep 17 00:00:00 2001 From: klim0v Date: Thu, 8 Sep 2022 16:01:22 +0300 Subject: [PATCH 47/48] fix estimate_coin_sell_all with route --- api/v2/service/estimate_coin_sell_all.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v2/service/estimate_coin_sell_all.go b/api/v2/service/estimate_coin_sell_all.go index d37a3517a..f52d3a61d 100644 --- a/api/v2/service/estimate_coin_sell_all.go +++ b/api/v2/service/estimate_coin_sell_all.go @@ -129,7 +129,7 @@ func (s *Service) EstimateCoinSellAll(ctx context.Context, req *pb.EstimateCoinS valueBancor, errBancor = s.calcSellAllFromBancor(valueToSell, coinTo, coinFrom, commissionInBaseCoin) } if req.SwapFrom == pb.SwapFrom_pool || req.SwapFrom == pb.SwapFrom_optimal { - commissionInBaseCoin := new(big.Int).Set(commissions.SellAllPoolBase) + commissionInBaseCoin := new(big.Int).Add(commissions.SellAllPoolBase, new(big.Int).Mul(commissions.SellAllPoolDelta, big.NewInt(int64(len(req.Route))))) if !commissions.Coin.IsBaseCoin() { commissionInBaseCoin, _ = cState.Swap().GetSwapper(types.GetBaseCoinID(), commissions.Coin).CalculateSellForBuyWithOrders(commissionInBaseCoin) } From e81dc315e558000080669476f4349127056913ea Mon Sep 17 00:00:00 2001 From: klim0v Date: Thu, 8 Sep 2022 16:12:03 +0300 Subject: [PATCH 48/48] enable V340 --- coreV2/minter/blockchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreV2/minter/blockchain.go b/coreV2/minter/blockchain.go index 804057fda..304d3928b 100644 --- a/coreV2/minter/blockchain.go +++ b/coreV2/minter/blockchain.go @@ -161,7 +161,7 @@ func NewMinterBlockchain(storages *utils.Storage, cfg *config.Config, ctx contex V310: {}, // hotfix V320: {}, V330: {}, - //V340: {}, // TODO: Only for release version + V340: {}, // TODO: Only for release version }, executor: GetExecutor(V3), }