main_dhc_test.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. package main
  2. import (
  3. "f1-game/internal/enum"
  4. "f1-game/internal/pb"
  5. "f1-game/tool/client-cli/cli"
  6. "fmt"
  7. "math/rand"
  8. "sync"
  9. "testing"
  10. "time"
  11. cherryHttp "github.com/cherry-game/cherry/extend/http"
  12. ctime "github.com/cherry-game/cherry/extend/time"
  13. clog "github.com/cherry-game/cherry/logger"
  14. )
  15. func testDHCSetup() *cli.Robot {
  16. var (
  17. // url = "http://192.168.1.232:18080"
  18. // addr = "192.168.1.232:30001"
  19. url = "http://dev.f1.chun-pu.com"
  20. addr = "127.0.0.1:30001"
  21. serverId = "4"
  22. account = "dhc-030901"
  23. password = "123456"
  24. pid = "2188004"
  25. )
  26. cli.RegisterDevAccount(url, account, password)
  27. robot := cli.EnterServer(url, pid, account, password, addr, serverId, true)
  28. return robot
  29. }
  30. func TestDHCMain(t *testing.T) {
  31. testDHCSetup()
  32. select {}
  33. }
  34. func TestDHCMainMap(t *testing.T) {
  35. robot := testDHCSetup()
  36. robot.MapLogin()
  37. time.Sleep(3 * time.Second)
  38. // robot.JoinLeague(1898)
  39. // robot.MapMarch(1, enum.MarchType_Siege, 63, 755, false, false)
  40. // time.Sleep(3 * time.Second)
  41. // robot.MapMarch(2, enum.MarchType_Siege, 63, 755, false, false)
  42. // time.Sleep(3 * time.Second)
  43. // robot.MapMarch(3, enum.MarchType_Siege, 63, 755, false, false)
  44. // time.Sleep(3 * time.Second)
  45. // robot.MapMarch(1, enum.MarchType_Occupy, 72, 712, false, true)
  46. // time.Sleep(3 * time.Second)
  47. // robot.MapMarch(2, enum.MarchType_Assemble, 63, 755, false, true)
  48. // time.Sleep(3 * time.Second)
  49. // robot.MapMarch(3, enum.MarchType_Assemble, 63, 755, false, false)
  50. // time.Sleep(3 * time.Second)
  51. // robot.MapStop(1)
  52. // time.Sleep(3 * time.Second)
  53. // robot.MapRetreat(1, 0)
  54. // time.Sleep(3 * time.Second)
  55. select {}
  56. }
  57. // 获取赛季霸业任务
  58. func TestSeasonQuestInfo(t *testing.T) {
  59. robot := testDHCSetup()
  60. time.Sleep(1 * time.Second)
  61. robot.MapLogin()
  62. time.Sleep(1 * time.Second)
  63. robot.SeasonQuestInfo()
  64. }
  65. // 领取赛季霸业奖励
  66. func TestSeasonQuestReward(t *testing.T) {
  67. robot := testDHCSetup()
  68. time.Sleep(1 * time.Second)
  69. robot.MapLogin()
  70. time.Sleep(1 * time.Second)
  71. questID := int32(101)
  72. robot.SeasonQuestReward(questID)
  73. select {}
  74. }
  75. // 地图交易所货柜解锁
  76. func TestExchangeSlotUnlock(t *testing.T) {
  77. robot := testDHCSetup()
  78. time.Sleep(1 * time.Second)
  79. robot.MapLogin()
  80. time.Sleep(1 * time.Second)
  81. robot.ExchangeSlotUnlock(enum.ExchangeActType_Sell)
  82. select {}
  83. }
  84. // 获取资源的历史求购价格
  85. func TestExchangeHistoryPrice(t *testing.T) {
  86. robot := testDHCSetup()
  87. time.Sleep(1 * time.Second)
  88. robot.MapLogin()
  89. time.Sleep(1 * time.Second)
  90. robot.ExchangeHistoryPrice(101)
  91. select {}
  92. }
  93. // 交易所交易物品
  94. func TestExchangeItem(t *testing.T) {
  95. robot := testDHCSetup()
  96. time.Sleep(1 * time.Second)
  97. robot.MapLogin()
  98. time.Sleep(1 * time.Second)
  99. robot.ExchangeItem(enum.ExchangeActType_Wish, enum.ItemIDIron, 1, 1)
  100. // time.Sleep(50 * time.Millisecond)
  101. // transID := robot.ExchangeMyItems(enum.ExchangeActType_Wish)
  102. // if transID != "" {
  103. // time.Sleep(50 * time.Millisecond)
  104. // robot.ExchangeItemUpdate(enum.ExchangeUpdateType_Retrieve, transID)
  105. // }
  106. // for _, itemID := range enum.ItemMaxNumList {
  107. // robot.ExchangeItem(enum.ExchangeActType_Sell, itemID, 1+rand.Int63n(4), 10+rand.Int31n(10))
  108. // time.Sleep(1 * time.Second)
  109. // }
  110. select {}
  111. }
  112. // 购买商品
  113. func TestExchangeBuyItem(t *testing.T) {
  114. robot := testDHCSetup()
  115. time.Sleep(1 * time.Second)
  116. robot.MapLogin()
  117. time.Sleep(1 * time.Second)
  118. transID := "yh8ZYN6Y9dyrUdxqOm6jxb"
  119. count := int32(1)
  120. robot.ExchangeBuyItem(count, transID)
  121. select {}
  122. }
  123. // 查询交易所交易物品
  124. func TestExchangeQuery(t *testing.T) {
  125. robot := testDHCSetup()
  126. time.Sleep(1 * time.Second)
  127. robot.MapLogin()
  128. time.Sleep(1 * time.Second)
  129. var (
  130. pageNum int32 = 1
  131. itemIDList = []int32{}
  132. subTypeList = []int32{}
  133. qualityList = []int32{}
  134. priceSort = enum.ExchangeSortType_None
  135. countSort = enum.ExchangeSortType_None
  136. )
  137. robot.ExchangeQuery(pageNum, itemIDList, subTypeList, qualityList, priceSort, countSort)
  138. select {}
  139. }
  140. // 获取自己的交易商品列表
  141. func TestExchangeMyItems(t *testing.T) {
  142. robot := testDHCSetup()
  143. time.Sleep(1 * time.Second)
  144. robot.MapLogin()
  145. time.Sleep(1 * time.Second)
  146. robot.ExchangeMyItems(enum.ExchangeActType_Sell)
  147. select {}
  148. }
  149. // 更新地图交易所商品
  150. func TestExchangeItemUpdate(t *testing.T) {
  151. robot := testDHCSetup()
  152. time.Sleep(1 * time.Second)
  153. robot.MapLogin()
  154. time.Sleep(1 * time.Second)
  155. transID := "WvzFHxz2YM2YFhuQEYWpI2"
  156. updateType := enum.ExchangeUpdateType_Cancel
  157. robot.ExchangeItemUpdate(updateType, transID)
  158. time.Sleep(1 * time.Second)
  159. var (
  160. pageNum int32 = 1
  161. itemIDList = []int32{}
  162. subTypeList = []int32{}
  163. qualityList = []int32{}
  164. priceSort = enum.ExchangeSortType_Asc
  165. countSort = enum.ExchangeSortType_Desc
  166. )
  167. robot.ExchangeQuery(pageNum, itemIDList, subTypeList, qualityList, priceSort, countSort)
  168. select {}
  169. }
  170. // 获取交易所日志
  171. func TestExchangeLog(t *testing.T) {
  172. robot := testDHCSetup()
  173. time.Sleep(1 * time.Second)
  174. robot.MapLogin()
  175. time.Sleep(1 * time.Second)
  176. logType := enum.ExchangeLogType_Sell
  177. lastLogID := int64(0)
  178. robot.ExchangeLog(logType, lastLogID)
  179. select {}
  180. }
  181. // 获取联盟仓库信息
  182. func TestLeagueStorage(t *testing.T) {
  183. robot := testDHCSetup()
  184. time.Sleep(1 * time.Second)
  185. robot.MapLogin()
  186. time.Sleep(3 * time.Second)
  187. robot.LeagueStorageInfo()
  188. select {}
  189. }
  190. // 联盟调整税率
  191. func TestLeagueRatioUpdate(t *testing.T) {
  192. robot := testDHCSetup()
  193. time.Sleep(1 * time.Second)
  194. robot.MapLogin()
  195. time.Sleep(3 * time.Second)
  196. robot.LeagueRatioUpdate(20201, 10)
  197. select {}
  198. }
  199. // 联盟F币分红
  200. func TestLeagueFundBonus(t *testing.T) {
  201. robot := testDHCSetup()
  202. time.Sleep(1 * time.Second)
  203. robot.LeagueFundBonus(100, 12121, 112313)
  204. select {}
  205. }
  206. // 获取联盟城池列表
  207. func TestLeagueCastleList(t *testing.T) {
  208. robot := testDHCSetup()
  209. time.Sleep(1 * time.Second)
  210. robot.GetLeagueCastleList()
  211. }
  212. // 联盟城池城主任命
  213. func TestLeagueCastleAppoint(t *testing.T) {
  214. robot := testDHCSetup()
  215. time.Sleep(1 * time.Second)
  216. robot.LeagueCastleAppoint(101001, 1049132)
  217. }
  218. // 获取联盟科技列表
  219. func TestLeagueTechList(t *testing.T) {
  220. robot := testDHCSetup()
  221. time.Sleep(1 * time.Second)
  222. robot.GetLeagueTechList()
  223. }
  224. // 联盟科技升级
  225. func TestLeagueTechUpgrade(t *testing.T) {
  226. robot := testDHCSetup()
  227. time.Sleep(1 * time.Second)
  228. robot.LeagueTechUpgrade(1001)
  229. }
  230. // 英雄上阵
  231. func TestHeroLineupUp(t *testing.T) {
  232. robot := testDHCSetup()
  233. time.Sleep(1 * time.Second)
  234. robot.TeamUp(1049155, 1, 1, 1)
  235. time.Sleep(500 * time.Microsecond)
  236. // robot.TeamLeave(1, 1)
  237. // time.Sleep(500 * time.Microsecond)
  238. // robot.TeamUp(1048889, 1, 2, 3)
  239. // time.Sleep(500 * time.Microsecond)
  240. // robot.TeamUp(1048898, 1, 3, 5)
  241. // time.Sleep(500 * time.Microsecond)
  242. }
  243. // 获取个人战报列表
  244. func TestReportList(t *testing.T) {
  245. robot := testDHCSetup()
  246. time.Sleep(1 * time.Second)
  247. robot.MapLogin()
  248. time.Sleep(1 * time.Second)
  249. robot.ReportList("", enum.ReportCategory_All)
  250. select {}
  251. }
  252. // 获取个人收藏战报列表
  253. func TestReportInfo(t *testing.T) {
  254. robot := testDHCSetup()
  255. time.Sleep(1 * time.Second)
  256. robot.ReportInfo()
  257. }
  258. // 战报收藏和取消收藏
  259. func TestReportLike(t *testing.T) {
  260. robot := testDHCSetup()
  261. time.Sleep(1 * time.Second)
  262. robot.ReportLike(enum.ReportLikeType_Group, "1001", false)
  263. }
  264. // 战报一键阅读
  265. func TestReportRead(t *testing.T) {
  266. robot := testDHCSetup()
  267. time.Sleep(1 * time.Second)
  268. robot.ReportRead("")
  269. }
  270. // 获取同盟战报列表
  271. func TestLeagueReportList(t *testing.T) {
  272. robot := testDHCSetup()
  273. time.Sleep(1 * time.Second)
  274. robot.LeagueReportList(0, enum.ReportCategory_PVP)
  275. select {}
  276. }
  277. // 发起探险战斗
  278. func TestChapterBattle(t *testing.T) {
  279. robot := testDHCSetup()
  280. time.Sleep(1 * time.Second)
  281. robot.ChapterBattle(1011)
  282. }
  283. // 探险战斗验证
  284. func TestChapterVerify(t *testing.T) {
  285. robot := testDHCSetup()
  286. time.Sleep(1 * time.Second)
  287. robot.ChapterVerify(enum.BattleCampType_Left)
  288. }
  289. // 发送聊天消息
  290. func TestChatSend(t *testing.T) {
  291. robot := testDHCSetup()
  292. for i := range 1 {
  293. time.Sleep(1 * time.Second)
  294. robot.ChatSend(enum.ChatType_Game, 4, fmt.Sprintf("hello TestDHC%d", i))
  295. }
  296. select {}
  297. }
  298. // 聊天消息获取
  299. func TestChatMsgList(t *testing.T) {
  300. robot := testDHCSetup()
  301. time.Sleep(1 * time.Second)
  302. // robot.MapLogin()
  303. // time.Sleep(1 * time.Second)
  304. robot.ChatMsgList(enum.ChatType_Game, 4, 656893032578399168)
  305. select {}
  306. }
  307. // 创建聊天群组
  308. func TestChatGroupCreate(t *testing.T) {
  309. robot := testDHCSetup()
  310. time.Sleep(1 * time.Second)
  311. robot.ChatGroupCreate("h4", 1066402)
  312. select {}
  313. }
  314. // 群组成员修改
  315. func TestChatGroupPlayerChange(t *testing.T) {
  316. robot := testDHCSetup()
  317. time.Sleep(1 * time.Second)
  318. robot.ChatGroupPlayerChange(1025, []int64{1066353})
  319. select {}
  320. }
  321. // 群组邀请确认
  322. func TestChatGroupInviteConfirm(t *testing.T) {
  323. robot := testDHCSetup()
  324. robot.ChatGroupInviteConfirm(1028, true)
  325. }
  326. // 获取群组成员列表
  327. func TestChatGroupPlayerList(t *testing.T) {
  328. robot := testDHCSetup()
  329. time.Sleep(1 * time.Second)
  330. robot.ChatGroupPlayerList(1028)
  331. }
  332. // 解散群组
  333. func TestChatGroupDismiss(t *testing.T) {
  334. robot := testDHCSetup()
  335. time.Sleep(1 * time.Second)
  336. robot.ChatGroupDismiss(1030)
  337. }
  338. // 主动退出群组
  339. func TestChatGroupQuit(t *testing.T) {
  340. robot := testDHCSetup()
  341. time.Sleep(1 * time.Second)
  342. robot.ChatGroupQuit(1027)
  343. }
  344. // 设置群组聊天免打扰
  345. func TestGroupChatNofitySetting(t *testing.T) {
  346. robot := testDHCSetup()
  347. time.Sleep(1 * time.Second)
  348. robot.ChatGroupMute(1031, false)
  349. }
  350. // 私聊发送消息
  351. func TestChatPrivateSend(t *testing.T) {
  352. robot := testDHCSetup()
  353. time.Sleep(3 * time.Second)
  354. for i := 0; i < 1; i++ {
  355. robot.ChatPrivateSend(1048857, fmt.Sprintf("测试私聊消息4 hello I am dhc-test %d", i))
  356. time.Sleep(3 * time.Second)
  357. }
  358. select {}
  359. }
  360. // 获取私聊消息列表
  361. func TestChatPrivateMsgList(t *testing.T) {
  362. robot := testDHCSetup()
  363. time.Sleep(1 * time.Second)
  364. robot.ChatPrivateMsgList(1066419, 0)
  365. }
  366. // 聊天设置
  367. func TestChatSetting(t *testing.T) {
  368. robot := testDHCSetup()
  369. time.Sleep(1 * time.Second)
  370. robot.ChatSetting(false, false, false)
  371. }
  372. // 查询玩家信息
  373. func TestFriendSearch(t *testing.T) {
  374. robot := testDHCSetup()
  375. time.Sleep(1 * time.Second)
  376. robot.FriendSearch(1048584)
  377. }
  378. // 添加好友
  379. func TestFriendAdd(t *testing.T) {
  380. robot := testDHCSetup()
  381. time.Sleep(1 * time.Second)
  382. robot.FriendAdd(1066406)
  383. select {}
  384. }
  385. // 好友邀请确认
  386. func TestFriendConfirm(t *testing.T) {
  387. robot := testDHCSetup()
  388. time.Sleep(1 * time.Second)
  389. robot.FriendConfirm(1066408, true)
  390. select {}
  391. }
  392. // 删除好友
  393. func TestFriendDel(t *testing.T) {
  394. robot := testDHCSetup()
  395. time.Sleep(1 * time.Second)
  396. robot.FriendDel(1066408)
  397. select {}
  398. }
  399. // 设置黑名单
  400. func TestBlackSetting(t *testing.T) {
  401. robot := testDHCSetup()
  402. time.Sleep(1 * time.Second)
  403. robot.BlackSetting(1066355, false)
  404. select {}
  405. }
  406. // 举报
  407. func TestComplaint(t *testing.T) {
  408. robot := testDHCSetup()
  409. time.Sleep(1 * time.Second)
  410. robot.Complaint(1048585, enum.ComplaintType_BadName, "")
  411. }
  412. // 建筑升级
  413. func TestFacilityUp(t *testing.T) {
  414. robot := testDHCSetup()
  415. time.Sleep(1 * time.Second)
  416. robot.FacilityUp(1)
  417. }
  418. // 建筑取消升级
  419. func TestFacilityCancel(t *testing.T) {
  420. robot := testDHCSetup()
  421. time.Sleep(1 * time.Second)
  422. robot.FacilityCancel(1)
  423. }
  424. // 建筑立即升级完成
  425. func TestFacilityFinish(t *testing.T) {
  426. robot := testDHCSetup()
  427. time.Sleep(1 * time.Second)
  428. robot.FacilityFinish(1)
  429. }
  430. // 建筑队列解锁
  431. func TestFacilityQueueUnlock(t *testing.T) {
  432. robot := testDHCSetup()
  433. time.Sleep(1 * time.Second)
  434. robot.FacilityQueueUnlock(2)
  435. }
  436. // 支付测试
  437. func TestPayment(t *testing.T) {
  438. reqURL := "http://127.0.0.1/pay/test_payment?orderID=602573286605938496"
  439. cherryHttp.GET(reqURL)
  440. }
  441. // 英雄穿戴装备
  442. func TestHeroWearEquip(t *testing.T) {
  443. robot := testDHCSetup()
  444. time.Sleep(1 * time.Second)
  445. robot.HeroWearEquip(&pb.HeroEquip{
  446. HeroGUID: 1048603,
  447. EquipGUIDList: []int64{1048661, 1048642, 1048660},
  448. })
  449. select {}
  450. }
  451. // 英雄脱下装备
  452. func TestHeroTakeOffEquip(t *testing.T) {
  453. robot := testDHCSetup()
  454. time.Sleep(1 * time.Second)
  455. robot.HeroTakeOffEquip(&pb.I64I64{
  456. Key: 1048603,
  457. Value: 0,
  458. })
  459. select {}
  460. }
  461. // 领取每日VIP奖励
  462. func TestVipDailyReward(t *testing.T) {
  463. robot := testDHCSetup()
  464. time.Sleep(1 * time.Second)
  465. robot.VipDailyReward(enum.VipDailyRewardType_Exp)
  466. select {}
  467. }
  468. // 使用道具
  469. func TestDHCItemUse(t *testing.T) {
  470. robot := testDHCSetup()
  471. time.Sleep(1 * time.Second)
  472. robot.MapLogin()
  473. time.Sleep(1 * time.Second)
  474. robot.ItemUse(140003, 3)
  475. select {}
  476. }
  477. func Test_dhc_RegisterDevAccount(t *testing.T) {
  478. var (
  479. url = "http://192.168.1.225:18080"
  480. accountNum = 10000
  481. )
  482. accountList := make(map[string]string)
  483. for i := 1; i <= accountNum; i++ {
  484. key := fmt.Sprintf("dhc_%d", i)
  485. accountList[key] = key
  486. }
  487. cli.RegisterDevAccounts(url, accountList)
  488. }
  489. func Test_dhc_EnterServer(t *testing.T) {
  490. var (
  491. url = "http://192.168.1.225:18080"
  492. addr = "192.168.1.225:30001"
  493. gameNodeID = "4"
  494. testAccounts = make(map[string]string)
  495. pid = "2188004"
  496. maxAccountNum = 500
  497. )
  498. for i := 1; i <= maxAccountNum; i++ {
  499. key := fmt.Sprintf("dhc_122910_%d", i)
  500. testAccounts[key] = key
  501. cli.RegisterDevAccount(url, key, key)
  502. }
  503. now := ctime.Now()
  504. wg := &sync.WaitGroup{}
  505. wg.Add(maxAccountNum)
  506. for userName, password := range testAccounts {
  507. go func(userName, password string) {
  508. time.Sleep(50 + (time.Duration(rand.Int31n(100)) * time.Millisecond))
  509. robot := cli.EnterServer(url, pid, userName, password, addr, gameNodeID, false)
  510. robot.RandSleep()
  511. robot.MapLogin()
  512. wg.Done()
  513. }(userName, password)
  514. }
  515. wg.Wait()
  516. clog.Infof("elapsedTime = %dms", now.NowDiffMillisecond())
  517. }