utils_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. package txverifier
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/big"
  6. "reflect"
  7. "slices"
  8. "testing"
  9. "github.com/ethereum/go-ethereum/common"
  10. "github.com/wormhole-foundation/wormhole/sdk/vaa"
  11. )
  12. func TestExtractFromJsonPath(t *testing.T) {
  13. testcases := []struct {
  14. name string
  15. data json.RawMessage
  16. path string
  17. expected interface{}
  18. wantErr bool
  19. typ string
  20. }{
  21. {
  22. name: "ValidPathString",
  23. data: json.RawMessage(`{"key1": {"key2": "value"}}`),
  24. path: "key1.key2",
  25. expected: "value",
  26. wantErr: false,
  27. typ: "string",
  28. },
  29. {
  30. name: "ValidPathFloat",
  31. data: json.RawMessage(`{"key1": {"key2": 123.45}}`),
  32. path: "key1.key2",
  33. expected: 123.45,
  34. wantErr: false,
  35. typ: "float64",
  36. },
  37. {
  38. name: "InvalidPath",
  39. data: json.RawMessage(`{"key1": {"key2": "value"}}`),
  40. path: "key1.key3",
  41. expected: nil,
  42. wantErr: true,
  43. typ: "string",
  44. },
  45. {
  46. name: "NestedPath",
  47. data: json.RawMessage(`{"key1": {"key2": {"key3": "value"}}}`),
  48. path: "key1.key2.key3",
  49. expected: "value",
  50. wantErr: false,
  51. typ: "string",
  52. },
  53. {
  54. name: "EmptyPath",
  55. data: json.RawMessage(`{"key1": {"key2": "value"}}`),
  56. path: "",
  57. expected: nil,
  58. wantErr: true,
  59. typ: "string",
  60. },
  61. {
  62. name: "NonExistentPath",
  63. data: json.RawMessage(`{"key1": {"key2": "value"}}`),
  64. path: "key3.key4",
  65. expected: nil,
  66. wantErr: true,
  67. typ: "string",
  68. },
  69. {
  70. name: "MalformedJson",
  71. data: json.RawMessage(`{"key1": {"key2": "value"`),
  72. path: "key1.key2",
  73. expected: nil,
  74. wantErr: true,
  75. typ: "string",
  76. },
  77. {
  78. name: "DataIsNil",
  79. data: nil,
  80. path: "test",
  81. expected: nil,
  82. wantErr: true,
  83. typ: "string",
  84. },
  85. }
  86. for _, tt := range testcases {
  87. t.Run(tt.name, func(t *testing.T) {
  88. var result interface{}
  89. var err error
  90. switch tt.typ {
  91. case "string":
  92. var res string
  93. res, err = extractFromJsonPath[string](tt.data, tt.path)
  94. result = res
  95. case "float64":
  96. var res float64
  97. res, err = extractFromJsonPath[float64](tt.data, tt.path)
  98. result = res
  99. default:
  100. t.Fatalf("Unsupported type: %v", tt.typ)
  101. }
  102. if (err != nil) != tt.wantErr {
  103. t.Errorf("Expected error: %v, got: %v", tt.wantErr, err)
  104. }
  105. if !tt.wantErr && result != tt.expected {
  106. t.Errorf("Expected %v, got %v", tt.expected, result)
  107. }
  108. })
  109. }
  110. }
  111. func TestNormalize(t *testing.T) {
  112. testcases := []struct {
  113. name string
  114. amount *big.Int
  115. decimals uint8
  116. expected *big.Int
  117. }{
  118. {
  119. name: "AmountWithMoreThan8Decimals",
  120. amount: big.NewInt(1000000000000000000),
  121. decimals: 18,
  122. expected: big.NewInt(100000000),
  123. },
  124. {
  125. name: "AmountWithExactly8Decimals",
  126. amount: big.NewInt(12345678),
  127. decimals: 8,
  128. expected: big.NewInt(12345678),
  129. },
  130. {
  131. name: "AmountWithLessThan8Decimals",
  132. amount: big.NewInt(12345),
  133. decimals: 5,
  134. expected: big.NewInt(12345),
  135. },
  136. {
  137. name: "AmountWithZeroDecimals",
  138. amount: big.NewInt(12345678),
  139. decimals: 0,
  140. expected: big.NewInt(12345678),
  141. },
  142. {
  143. name: "AmountWith9Decimals",
  144. amount: big.NewInt(123456789),
  145. decimals: 9,
  146. expected: big.NewInt(12345678),
  147. },
  148. {
  149. name: "AmountWith10Decimals",
  150. amount: big.NewInt(1234567890),
  151. decimals: 10,
  152. expected: big.NewInt(12345678),
  153. },
  154. {
  155. name: "AmountEqualsNil",
  156. amount: nil,
  157. decimals: 18,
  158. expected: nil,
  159. },
  160. }
  161. for _, tt := range testcases {
  162. t.Run(tt.name, func(t *testing.T) {
  163. result := normalize(tt.amount, tt.decimals)
  164. if result.Cmp(tt.expected) != 0 {
  165. t.Errorf("Expected %v, got %v", tt.expected, result)
  166. }
  167. })
  168. }
  169. }
  170. func TestDenormalize(t *testing.T) {
  171. t.Parallel() // marks TLog as capable of running in parallel with other tests
  172. tests := map[string]struct {
  173. amount *big.Int
  174. decimals uint8
  175. expected *big.Int
  176. }{
  177. "noop: decimals less than 8": {
  178. amount: big.NewInt(123000),
  179. decimals: 1,
  180. expected: big.NewInt(123000),
  181. },
  182. "noop: decimals equal to 8": {
  183. amount: big.NewInt(123000),
  184. decimals: 8,
  185. expected: big.NewInt(123000),
  186. },
  187. "denormalize: decimals greater than 8": {
  188. amount: big.NewInt(123000),
  189. decimals: 12,
  190. expected: big.NewInt(1230000000),
  191. },
  192. // NOTE: some tokens on NEAR have as many as 24 decimals so this isn't a strict limit for Wormhole
  193. // overall, but should be true for EVM chains.
  194. "denormalize: decimals at maximum expected size": {
  195. amount: big.NewInt(123_000_000),
  196. decimals: 18,
  197. expected: big.NewInt(1_230_000_000_000_000_000),
  198. },
  199. // https://github.com/wormhole-foundation/wormhole/blob/main/whitepapers/0003_token_bridge.md#handling-of-token-amounts-and-decimals
  200. "denormalize: whitepaper example 1": {
  201. amount: big.NewInt(100000000),
  202. decimals: 18,
  203. expected: big.NewInt(1000000000000000000),
  204. },
  205. "denormalize: whitepaper example 2": {
  206. amount: big.NewInt(20000),
  207. decimals: 4,
  208. expected: big.NewInt(20000),
  209. },
  210. }
  211. for name, test := range tests {
  212. test := test // NOTE: uncomment for Go < 1.22, see /doc/faq#closures_and_goroutines
  213. t.Run(name, func(t *testing.T) {
  214. t.Parallel() // marks each test case as capable of running in parallel with each other
  215. if got := denormalize(test.amount, test.decimals); got.Cmp(test.expected) != 0 {
  216. t.Fatalf("denormalize(%s, %d) returned %s; expected %s",
  217. test.amount.String(),
  218. test.decimals,
  219. got,
  220. test.expected.String(),
  221. )
  222. }
  223. })
  224. }
  225. }
  226. func TestValidateChains(t *testing.T) {
  227. type args struct {
  228. input []uint
  229. }
  230. tests := []struct {
  231. name string
  232. args args
  233. want []vaa.ChainID
  234. wantErr bool
  235. }{
  236. {
  237. name: "invalid chainId",
  238. args: args{
  239. input: []uint{65535},
  240. },
  241. want: nil,
  242. wantErr: true,
  243. },
  244. {
  245. name: "unsupported chainId",
  246. args: args{
  247. input: []uint{22},
  248. },
  249. want: nil,
  250. wantErr: true,
  251. },
  252. {
  253. name: "empty input",
  254. args: args{
  255. input: []uint{},
  256. },
  257. want: nil,
  258. wantErr: true,
  259. },
  260. {
  261. name: "happy path",
  262. args: args{
  263. input: []uint{2},
  264. },
  265. want: []vaa.ChainID{vaa.ChainIDEthereum},
  266. wantErr: false,
  267. },
  268. }
  269. for _, tt := range tests {
  270. t.Run(tt.name, func(t *testing.T) {
  271. got, err := ValidateChains(tt.args.input)
  272. if (err != nil) != tt.wantErr {
  273. t.Errorf("ValidateChains() error = %v, wantErr %v", err, tt.wantErr)
  274. return
  275. }
  276. if !reflect.DeepEqual(got, tt.want) {
  277. t.Errorf("ValidateChains() = %v, want %v", got, tt.want)
  278. }
  279. })
  280. }
  281. }
  282. func Test_deleteEntries_StringKeys(t *testing.T) {
  283. tests := []struct {
  284. name string
  285. setupCache func() *map[string]vaa.Address
  286. wantNumPruned int
  287. wantErr bool
  288. wantFinalLen int
  289. }{
  290. {
  291. name: "nil pointer",
  292. setupCache: func() *map[string]vaa.Address {
  293. return nil
  294. },
  295. wantNumPruned: 0,
  296. wantErr: true,
  297. },
  298. {
  299. name: "pointer to nil map",
  300. setupCache: func() *map[string]vaa.Address {
  301. var m map[string]vaa.Address = nil
  302. return &m
  303. },
  304. wantNumPruned: 0,
  305. wantErr: true,
  306. },
  307. {
  308. name: "cache within limits - no deletion needed",
  309. setupCache: func() *map[string]vaa.Address {
  310. m := make(map[string]vaa.Address)
  311. // Add entries below CacheMaxSize
  312. for i := range CacheMaxSize - 10 {
  313. m[fmt.Sprintf("key%d", i)] = vaa.Address{}
  314. }
  315. return &m
  316. },
  317. wantNumPruned: 0,
  318. wantErr: false,
  319. wantFinalLen: CacheMaxSize - 10,
  320. },
  321. {
  322. name: "cache exactly at limit - no deletion needed",
  323. setupCache: func() *map[string]vaa.Address {
  324. m := make(map[string]vaa.Address)
  325. for i := range CacheMaxSize {
  326. m[fmt.Sprintf("key%d", i)] = vaa.Address{}
  327. }
  328. return &m
  329. },
  330. wantNumPruned: 0,
  331. wantErr: false,
  332. wantFinalLen: CacheMaxSize,
  333. },
  334. {
  335. name: "cache way over limit - delete enough to reach CacheMaxSize",
  336. setupCache: func() *map[string]vaa.Address {
  337. m := make(map[string]vaa.Address)
  338. for i := range CacheMaxSize + 50 {
  339. m[fmt.Sprintf("key%d", i)] = vaa.Address{}
  340. }
  341. return &m
  342. },
  343. wantNumPruned: 50, // CacheMaxSize+50-CacheMaxSize = 50 (more than CacheDeleteCount)
  344. wantErr: false,
  345. wantFinalLen: CacheMaxSize,
  346. },
  347. {
  348. name: "small cache over limit",
  349. setupCache: func() *map[string]vaa.Address {
  350. m := make(map[string]vaa.Address)
  351. for i := range CacheMaxSize + 3 {
  352. m[fmt.Sprintf("key%d", i)] = vaa.Address{}
  353. }
  354. return &m
  355. },
  356. wantNumPruned: CacheDeleteCount, // max(10, 3) = 10
  357. wantErr: false,
  358. wantFinalLen: CacheMaxSize + 3 - CacheDeleteCount,
  359. },
  360. }
  361. for _, tt := range tests {
  362. t.Run(tt.name, func(t *testing.T) {
  363. cachePtr := tt.setupCache()
  364. // Store original length for verification
  365. var originalLen int
  366. if cachePtr != nil && *cachePtr != nil {
  367. originalLen = len(*cachePtr)
  368. }
  369. got, err := deleteEntries(cachePtr)
  370. // Check error expectation
  371. if (err != nil) != tt.wantErr {
  372. t.Errorf("deleteEntries() error = %v, wantErr %v", err, tt.wantErr)
  373. return
  374. }
  375. // Check return value
  376. if got != tt.wantNumPruned {
  377. t.Errorf("deleteEntries() returned %v, want %v", got, tt.wantNumPruned)
  378. return
  379. }
  380. // If no error expected, verify the cache state
  381. if !tt.wantErr && cachePtr != nil && *cachePtr != nil {
  382. finalLen := len(*cachePtr)
  383. if finalLen != tt.wantFinalLen {
  384. t.Errorf("deleteEntries() final cache length = %v, want %v (original: %v, deleted: %v)",
  385. finalLen, tt.wantFinalLen, originalLen, got)
  386. }
  387. // Verify that the returned count matches actual deletions
  388. expectedDeletions := originalLen - finalLen
  389. if got != expectedDeletions {
  390. t.Errorf("deleteEntries() returned %v deletions, but actual deletions = %v",
  391. got, expectedDeletions)
  392. }
  393. }
  394. })
  395. }
  396. }
  397. //nolint:gosec // Testing on the uint8 value types, but ranging over a size gives int. The truncation issues don't matter here.
  398. func Test_deleteEntries_AddressKeys(t *testing.T) {
  399. tests := []struct {
  400. name string
  401. setupCache func() *map[common.Address]uint8
  402. want int
  403. wantErr bool
  404. wantFinalLen int
  405. }{
  406. {
  407. name: "nil pointer",
  408. setupCache: func() *map[common.Address]uint8 {
  409. return nil
  410. },
  411. want: 0,
  412. wantErr: true,
  413. },
  414. {
  415. name: "pointer to nil map",
  416. setupCache: func() *map[common.Address]uint8 {
  417. var m map[common.Address]uint8 = nil
  418. return &m
  419. },
  420. want: 0,
  421. wantErr: true,
  422. },
  423. {
  424. name: "cache within limits - no deletion needed",
  425. setupCache: func() *map[common.Address]uint8 {
  426. m := make(map[common.Address]uint8)
  427. // Add entries below CacheMaxSize
  428. for i := range CacheMaxSize - 10 {
  429. // TODO needs to be common.Address
  430. m[common.BytesToAddress([]byte{byte(i)})] = uint8(i)
  431. }
  432. return &m
  433. },
  434. want: 0,
  435. wantErr: false,
  436. wantFinalLen: CacheMaxSize - 10,
  437. },
  438. {
  439. name: "cache exactly at limit - no deletion needed",
  440. setupCache: func() *map[common.Address]uint8 {
  441. m := make(map[common.Address]uint8)
  442. for i := range CacheMaxSize {
  443. m[common.BytesToAddress([]byte{byte(i)})] = uint8(i)
  444. }
  445. return &m
  446. },
  447. want: 0,
  448. wantErr: false,
  449. wantFinalLen: CacheMaxSize,
  450. },
  451. {
  452. name: "cache way over limit - delete enough to reach CacheMaxSize",
  453. setupCache: func() *map[common.Address]uint8 {
  454. m := make(map[common.Address]uint8)
  455. for i := range CacheMaxSize + 50 {
  456. m[common.BytesToAddress([]byte{byte(i)})] = uint8(i)
  457. }
  458. return &m
  459. },
  460. want: 50, // CacheMaxSize+50-CacheMaxSize = 50 (more than CacheDeleteCount)
  461. wantErr: false,
  462. wantFinalLen: CacheMaxSize,
  463. },
  464. {
  465. name: "small cache over limit",
  466. setupCache: func() *map[common.Address]uint8 {
  467. m := make(map[common.Address]uint8)
  468. for i := range CacheMaxSize + 3 {
  469. m[common.BytesToAddress([]byte{byte(i)})] = uint8(i)
  470. }
  471. return &m
  472. },
  473. want: CacheDeleteCount, // max(10, 3) = 10
  474. wantErr: false,
  475. wantFinalLen: CacheMaxSize + 3 - CacheDeleteCount,
  476. },
  477. }
  478. for _, tt := range tests {
  479. t.Run(tt.name, func(t *testing.T) {
  480. cachePtr := tt.setupCache()
  481. // Store original length for verification
  482. var originalLen int
  483. if cachePtr != nil && *cachePtr != nil {
  484. originalLen = len(*cachePtr)
  485. }
  486. got, err := deleteEntries(cachePtr)
  487. // Check error expectation
  488. if (err != nil) != tt.wantErr {
  489. t.Errorf("deleteEntries() error = %v, wantErr %v", err, tt.wantErr)
  490. return
  491. }
  492. // Check return value
  493. if got != tt.want {
  494. t.Errorf("deleteEntries() returned %v, want %v", got, tt.want)
  495. return
  496. }
  497. // If no error expected, verify the cache state
  498. if !tt.wantErr && cachePtr != nil && *cachePtr != nil {
  499. finalLen := len(*cachePtr)
  500. if finalLen != tt.wantFinalLen {
  501. t.Errorf("deleteEntries() final cache length = %v, want %v (original: %v, deleted: %v)",
  502. finalLen, tt.wantFinalLen, originalLen, got)
  503. }
  504. // Verify that the returned count matches actual deletions
  505. expectedDeletions := originalLen - finalLen
  506. if got != expectedDeletions {
  507. t.Errorf("deleteEntries() returned %v deletions, but actual deletions = %v",
  508. got, expectedDeletions)
  509. }
  510. }
  511. })
  512. }
  513. }
  514. func Test_validateSolvency(t *testing.T) {
  515. tests := []struct {
  516. name string
  517. requests MsgIdToRequestOutOfBridge
  518. transfers AssetKeyToTransferIntoBridge
  519. wantErr bool
  520. invalidTransfers []string
  521. }{
  522. {
  523. name: "SingleRequest_SingleAsset_Solvent",
  524. requests: MsgIdToRequestOutOfBridge{
  525. "msg1": {
  526. AssetKey: "asset1",
  527. Amount: big.NewInt(100),
  528. DepositMade: false,
  529. DepositSolvent: false, // will be updated by validateSolvency
  530. },
  531. },
  532. transfers: AssetKeyToTransferIntoBridge{
  533. "asset1": {
  534. Amount: big.NewInt(200),
  535. },
  536. },
  537. wantErr: false,
  538. invalidTransfers: []string{},
  539. },
  540. {
  541. name: "SingleRequest_SingleAsset_Insolvent",
  542. requests: MsgIdToRequestOutOfBridge{
  543. "msg1": {
  544. AssetKey: "asset1",
  545. Amount: big.NewInt(300),
  546. DepositMade: false,
  547. DepositSolvent: false, // will be updated by validateSolvency
  548. },
  549. },
  550. transfers: AssetKeyToTransferIntoBridge{
  551. "asset1": {
  552. Amount: big.NewInt(200),
  553. },
  554. },
  555. wantErr: false,
  556. invalidTransfers: []string{"msg1"},
  557. },
  558. {
  559. name: "MultipleRequests_MultipleAssets_MixedSolvency",
  560. requests: MsgIdToRequestOutOfBridge{
  561. "msg1": {
  562. AssetKey: "asset1",
  563. Amount: big.NewInt(100),
  564. DepositMade: false,
  565. DepositSolvent: false, // will be updated by validateSolvency
  566. },
  567. "msg2": {
  568. AssetKey: "asset2",
  569. Amount: big.NewInt(150),
  570. DepositMade: false,
  571. DepositSolvent: false, // will be updated by validateSolvency
  572. },
  573. "msg3": {
  574. AssetKey: "asset1",
  575. Amount: big.NewInt(50),
  576. DepositMade: false,
  577. DepositSolvent: false, // will be updated by validateSolvency
  578. },
  579. },
  580. transfers: AssetKeyToTransferIntoBridge{
  581. "asset1": {
  582. Amount: big.NewInt(120),
  583. },
  584. "asset2": {
  585. Amount: big.NewInt(200),
  586. },
  587. },
  588. wantErr: false,
  589. // asset1 is insolvent because of msg1 and msg3
  590. invalidTransfers: []string{"msg1", "msg3"},
  591. },
  592. {
  593. name: "RequestWithNoMatchingTransfer",
  594. requests: MsgIdToRequestOutOfBridge{
  595. "msg1": {
  596. AssetKey: "asset1",
  597. Amount: big.NewInt(100),
  598. DepositMade: false,
  599. DepositSolvent: false, // will be updated by validateSolvency
  600. },
  601. },
  602. transfers: AssetKeyToTransferIntoBridge{},
  603. wantErr: false,
  604. invalidTransfers: []string{"msg1"}, // no transfer for asset1
  605. },
  606. {
  607. name: "EmptyRequests",
  608. requests: MsgIdToRequestOutOfBridge{},
  609. transfers: AssetKeyToTransferIntoBridge{},
  610. wantErr: false,
  611. invalidTransfers: []string{},
  612. },
  613. {
  614. name: "EmptyTransfers",
  615. requests: MsgIdToRequestOutOfBridge{
  616. "msg1": {
  617. AssetKey: "asset1",
  618. Amount: big.NewInt(100),
  619. DepositMade: false,
  620. DepositSolvent: false, // will be updated by validateSolvency
  621. },
  622. },
  623. transfers: AssetKeyToTransferIntoBridge{},
  624. wantErr: false,
  625. invalidTransfers: []string{"msg1"}, // no transfer for asset1
  626. },
  627. {
  628. name: "EmptyRequests",
  629. requests: MsgIdToRequestOutOfBridge{},
  630. transfers: AssetKeyToTransferIntoBridge{},
  631. wantErr: false,
  632. invalidTransfers: []string{},
  633. },
  634. {
  635. name: "RequestWithNilAmount",
  636. requests: MsgIdToRequestOutOfBridge{
  637. "msg1": {
  638. AssetKey: "asset1",
  639. Amount: nil,
  640. DepositMade: false,
  641. DepositSolvent: false, // will be updated by validateSolvency
  642. },
  643. },
  644. transfers: AssetKeyToTransferIntoBridge{},
  645. wantErr: true,
  646. invalidTransfers: []string{},
  647. },
  648. {
  649. name: "TransferWithNilAmount",
  650. requests: MsgIdToRequestOutOfBridge{
  651. "msg1": {
  652. AssetKey: "asset1",
  653. Amount: big.NewInt(100),
  654. DepositMade: false,
  655. DepositSolvent: false, // will be updated by validateSolvency
  656. },
  657. },
  658. transfers: AssetKeyToTransferIntoBridge{
  659. "asset1": {
  660. Amount: nil,
  661. },
  662. },
  663. wantErr: true,
  664. invalidTransfers: []string{},
  665. },
  666. }
  667. for _, tt := range tests {
  668. t.Run(tt.name, func(t *testing.T) {
  669. resolved, err := validateSolvency(tt.requests, tt.transfers)
  670. if (err != nil) != tt.wantErr {
  671. t.Errorf("validateSolvency() error = %v, wantErr %v", err, tt.wantErr)
  672. return
  673. }
  674. for msgIdStr, req := range resolved {
  675. reqIsValid := req.DepositSolvent && req.DepositMade
  676. shouldBeInvalid := slices.Contains(tt.invalidTransfers, msgIdStr)
  677. if reqIsValid && !shouldBeInvalid {
  678. // Valid and should be valid, all good.
  679. } else if reqIsValid && shouldBeInvalid {
  680. // Request was marked as valid, but should be invalid
  681. t.Errorf("Expected message ID %s to be marked as invalid, but it was marked as valid", msgIdStr)
  682. } else if !reqIsValid && !shouldBeInvalid {
  683. // Request was marked as invalid, but should be valid
  684. t.Errorf("Expected message ID %s to be marked as valid, but it was marked as invalid", msgIdStr)
  685. }
  686. }
  687. })
  688. }
  689. }