11import should from 'should' ;
2- import { CosmosUtils } from '@bitgo/abstract-cosmos ' ;
2+ import { NetworkType } from '@bitgo/statics ' ;
33
4- import utils from '../../src/lib/utils' ;
4+ import utils , { HashUtils } from '../../src/lib/utils' ;
55import * as testData from '../resources/hash' ;
66import { blockHash , txIds , TEST_CONTRACT_CALL , TEST_GROUP_VOTE } from '../resources/hash' ;
77
88describe ( 'utils' , ( ) => {
9+ const testnetHashUtils = new HashUtils ( NetworkType . TESTNET ) ;
910 it ( 'should validate block hash correctly' , ( ) => {
1011 should . equal ( utils . isValidBlockId ( blockHash . hash1 ) , true ) ;
1112 should . equal ( utils . isValidBlockId ( blockHash . hash2 ) , true ) ;
@@ -48,7 +49,7 @@ describe('utils', () => {
4849
4950 describe ( 'decodeMsg' , ( ) => {
5051 it ( 'should detect valid base64-encoded group proposal' , ( ) => {
51- const result = CosmosUtils . decodeMsg ( TEST_CONTRACT_CALL . encodedProposal ) ;
52+ const result = testnetHashUtils . decodeMsg ( TEST_CONTRACT_CALL . encodedProposal ) ;
5253
5354 should . exist ( result . typeUrl ) ;
5455 if ( result . typeUrl ) {
@@ -58,28 +59,28 @@ describe('utils', () => {
5859 } ) ;
5960
6061 it ( 'should reject invalid base64 string' , ( ) => {
61- const result = CosmosUtils . decodeMsg ( 'not-valid-base64!!!' ) ;
62+ const result = testnetHashUtils . decodeMsg ( 'not-valid-base64!!!' ) ;
6263
6364 should . not . exist ( result . typeUrl ) ;
6465 should . exist ( result . error ) ;
6566 } ) ;
6667
6768 it ( 'should reject valid base64 but invalid protobuf' , ( ) => {
68- const result = CosmosUtils . decodeMsg ( Buffer . from ( 'random data' ) . toString ( 'base64' ) ) ;
69+ const result = testnetHashUtils . decodeMsg ( Buffer . from ( 'random data' ) . toString ( 'base64' ) ) ;
6970
7071 should . not . exist ( result . typeUrl ) ;
7172 should . exist ( result . error ) ;
7273 } ) ;
7374
7475 it ( 'should reject hex-encoded contract call data' , ( ) => {
75- const result = CosmosUtils . decodeMsg ( '7b22696e6372656d656e74223a7b7d7d' ) ;
76+ const result = testnetHashUtils . decodeMsg ( '7b22696e6372656d656e74223a7b7d7d' ) ;
7677
7778 should . not . exist ( result . typeUrl ) ;
7879 } ) ;
7980
8081 it ( 'should accept Uint8Array input' , ( ) => {
8182 const bytes = Buffer . from ( TEST_CONTRACT_CALL . encodedProposal , 'base64' ) ;
82- const result = CosmosUtils . decodeMsg ( bytes ) ;
83+ const result = testnetHashUtils . decodeMsg ( bytes ) ;
8384
8485 should . exist ( result . typeUrl ) ;
8586 if ( result . typeUrl ) {
@@ -90,7 +91,7 @@ describe('utils', () => {
9091
9192 describe ( 'decodeMsg - group vote' , ( ) => {
9293 it ( 'should detect valid base64-encoded group vote' , ( ) => {
93- const result = CosmosUtils . decodeMsg ( TEST_GROUP_VOTE . encodedVote ) ;
94+ const result = testnetHashUtils . decodeMsg ( TEST_GROUP_VOTE . encodedVote ) ;
9495
9596 should . exist ( result . typeUrl ) ;
9697 if ( result . typeUrl ) {
@@ -101,7 +102,7 @@ describe('utils', () => {
101102
102103 it ( 'should accept Uint8Array input for group vote' , ( ) => {
103104 const bytes = Buffer . from ( TEST_GROUP_VOTE . encodedVote , 'base64' ) ;
104- const result = CosmosUtils . decodeMsg ( bytes ) ;
105+ const result = testnetHashUtils . decodeMsg ( bytes ) ;
105106
106107 should . exist ( result . typeUrl ) ;
107108 if ( result . typeUrl ) {
@@ -117,7 +118,7 @@ describe('utils', () => {
117118 contract : 'tp12nyn83ynewtmpkw32wq6dg83wx8nqpat65gcld' ,
118119 msg : Buffer . from ( TEST_GROUP_VOTE . encodedVote , 'base64' ) ,
119120 } ;
120- should . equal ( CosmosUtils . isGroupVote ( message ) , true ) ;
121+ should . equal ( testnetHashUtils . isGroupVote ( message ) , true ) ;
121122 } ) ;
122123
123124 it ( 'should return false when msg contains a group proposal' , ( ) => {
@@ -126,7 +127,7 @@ describe('utils', () => {
126127 contract : 'tp12nyn83ynewtmpkw32wq6dg83wx8nqpat65gcld' ,
127128 msg : Buffer . from ( TEST_CONTRACT_CALL . encodedProposal , 'base64' ) ,
128129 } ;
129- should . equal ( CosmosUtils . isGroupVote ( message ) , false ) ;
130+ should . equal ( testnetHashUtils . isGroupVote ( message ) , false ) ;
130131 } ) ;
131132
132133 it ( 'should return false when msg is empty' , ( ) => {
@@ -135,7 +136,7 @@ describe('utils', () => {
135136 contract : 'tp12nyn83ynewtmpkw32wq6dg83wx8nqpat65gcld' ,
136137 msg : new Uint8Array ( 0 ) ,
137138 } ;
138- should . equal ( CosmosUtils . isGroupVote ( message ) , false ) ;
139+ should . equal ( testnetHashUtils . isGroupVote ( message ) , false ) ;
139140 } ) ;
140141 } ) ;
141142
@@ -146,7 +147,7 @@ describe('utils', () => {
146147 contract : 'tp12nyn83ynewtmpkw32wq6dg83wx8nqpat65gcld' ,
147148 msg : Buffer . from ( TEST_CONTRACT_CALL . encodedProposal , 'base64' ) ,
148149 } ;
149- should . equal ( CosmosUtils . isGroupProposal ( message ) , true ) ;
150+ should . equal ( testnetHashUtils . isGroupProposal ( message ) , true ) ;
150151 } ) ;
151152
152153 it ( 'should return false when msg contains regular contract call data' , ( ) => {
@@ -155,7 +156,7 @@ describe('utils', () => {
155156 contract : 'tp12nyn83ynewtmpkw32wq6dg83wx8nqpat65gcld' ,
156157 msg : Buffer . from ( JSON . stringify ( { increment : { } } ) ) ,
157158 } ;
158- should . equal ( CosmosUtils . isGroupProposal ( message ) , false ) ;
159+ should . equal ( testnetHashUtils . isGroupProposal ( message ) , false ) ;
159160 } ) ;
160161
161162 it ( 'should return false when msg is empty' , ( ) => {
@@ -164,7 +165,7 @@ describe('utils', () => {
164165 contract : 'tp12nyn83ynewtmpkw32wq6dg83wx8nqpat65gcld' ,
165166 msg : new Uint8Array ( 0 ) ,
166167 } ;
167- should . equal ( CosmosUtils . isGroupProposal ( message ) , false ) ;
168+ should . equal ( testnetHashUtils . isGroupProposal ( message ) , false ) ;
168169 } ) ;
169170 } ) ;
170171} ) ;
0 commit comments