@@ -3,7 +3,7 @@ import should from 'should';
33import sinon from 'sinon' ;
44import { getMessageBuilderFactory , registerMessageBuilderFactory } from '../../src' ;
55import { BaseMessageBuilderFactory , BuildMessageError } from '@bitgo/sdk-core' ;
6- import { coins , BaseCoin } from '@bitgo/statics' ;
6+ import { coins , BaseCoin , CoinFeature } from '@bitgo/statics' ;
77import { MockMessageBuilderFactory } from './fixtures' ;
88
99describe ( 'Message Builder Factory' , ( ) => {
@@ -30,6 +30,40 @@ describe('Message Builder Factory', () => {
3030 should . exist ( htethFactory ) ;
3131 htethFactory . should . be . instanceof ( BaseMessageBuilderFactory ) ;
3232 } ) ;
33+
34+ it ( 'should auto-register all non-token coins with SHARED_EVM_MESSAGE_SIGNING feature' , ( ) => {
35+ const evmCoins = coins . reduce < string [ ] > ( ( acc , coin ) => {
36+ if ( coin . features . includes ( CoinFeature . SHARED_EVM_MESSAGE_SIGNING ) && ! coin . isToken ) {
37+ acc . push ( coin . name ) ;
38+ }
39+ return acc ;
40+ } , [ ] ) ;
41+ evmCoins . length . should . be . greaterThan ( 0 ) ;
42+
43+ for ( const coinName of evmCoins ) {
44+ const factory = getMessageBuilderFactory ( coinName ) ;
45+ should . exist ( factory , `Expected message builder factory for ${ coinName } ` ) ;
46+ factory . should . be . instanceof ( BaseMessageBuilderFactory ) ;
47+ }
48+ } ) ;
49+
50+ it ( 'should not register token coins with SHARED_EVM_MESSAGE_SIGNING feature' , ( ) => {
51+ const evmTokens = coins . reduce < string [ ] > ( ( acc , coin ) => {
52+ if ( coin . features . includes ( CoinFeature . SHARED_EVM_MESSAGE_SIGNING ) && coin . isToken ) {
53+ acc . push ( coin . name ) ;
54+ }
55+ return acc ;
56+ } , [ ] ) ;
57+ evmTokens . length . should . be . greaterThan ( 0 ) ;
58+
59+ for ( const tokenName of evmTokens ) {
60+ assert . throws (
61+ ( ) => getMessageBuilderFactory ( tokenName ) ,
62+ ( e : Error ) => e instanceof BuildMessageError ,
63+ `Token ${ tokenName } should not have a message builder factory` ,
64+ ) ;
65+ }
66+ } ) ;
3367 } ) ;
3468
3569 describe ( 'registerMessageBuilderFactory' , ( ) => {
0 commit comments