|
| 1 | +import 'should'; |
| 2 | +import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test'; |
| 3 | +import { BitGoAPI } from '@bitgo/sdk-api'; |
| 4 | + |
| 5 | +import { register, MonToken } from '../../src'; |
| 6 | + |
| 7 | +describe('Mon Token:', function () { |
| 8 | + let bitgo: TestBitGoAPI; |
| 9 | + let monTokenCoin; |
| 10 | + const tokenName = 'mon:usdc'; |
| 11 | + |
| 12 | + before(function () { |
| 13 | + bitgo = TestBitGo.decorate(BitGoAPI, { env: 'prod' }); |
| 14 | + register(bitgo); |
| 15 | + bitgo.initializeTestVars(); |
| 16 | + monTokenCoin = bitgo.coin(tokenName); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should return constants', function () { |
| 20 | + monTokenCoin.getChain().should.equal('mon:usdc'); |
| 21 | + monTokenCoin.getBaseChain().should.equal('mon'); |
| 22 | + monTokenCoin.getFullName().should.equal('Mon Token'); |
| 23 | + monTokenCoin.getBaseFactor().should.equal(1e6); |
| 24 | + monTokenCoin.type.should.equal(tokenName); |
| 25 | + monTokenCoin.name.should.equal('Monad USDC'); |
| 26 | + monTokenCoin.coin.should.equal('mon'); |
| 27 | + monTokenCoin.network.should.equal('Mainnet'); |
| 28 | + monTokenCoin.decimalPlaces.should.equal(6); |
| 29 | + }); |
| 30 | + |
| 31 | + describe('Token Registration and TransactionBuilder', function () { |
| 32 | + const mainnetTokens = ['mon:usdc', 'mon:wmon']; |
| 33 | + |
| 34 | + describe('Mainnet tokens', function () { |
| 35 | + mainnetTokens.forEach((tokenName) => { |
| 36 | + it(`${tokenName} should be registered as MonToken`, function () { |
| 37 | + const token = bitgo.coin(tokenName); |
| 38 | + token.should.be.instanceOf(MonToken); |
| 39 | + }); |
| 40 | + |
| 41 | + it(`${tokenName} should create TransactionBuilder without error`, function () { |
| 42 | + const token = bitgo.coin(tokenName) as MonToken; |
| 43 | + // @ts-expect-error - accessing protected method for testing |
| 44 | + (() => token.getTransactionBuilder()).should.not.throw(); |
| 45 | + }); |
| 46 | + |
| 47 | + it(`${tokenName} should use Mon-specific TransactionBuilder`, function () { |
| 48 | + const token = bitgo.coin(tokenName) as MonToken; |
| 49 | + // @ts-expect-error - accessing protected method for testing |
| 50 | + const builder = token.getTransactionBuilder(); |
| 51 | + builder.should.have.property('_common'); |
| 52 | + builder.constructor.name.should.equal('TransactionBuilder'); |
| 53 | + }); |
| 54 | + |
| 55 | + it(`${tokenName} should not throw "Cannot use common sdk module" error`, function () { |
| 56 | + const token = bitgo.coin(tokenName) as MonToken; |
| 57 | + let errorThrown = false; |
| 58 | + let errorMessage = ''; |
| 59 | + |
| 60 | + try { |
| 61 | + // @ts-expect-error - accessing protected method for testing |
| 62 | + const builder = token.getTransactionBuilder(); |
| 63 | + // Try to use the builder to ensure it's fully functional |
| 64 | + // @ts-expect-error - type expects TransactionType enum |
| 65 | + builder.type('Send'); |
| 66 | + } catch (e) { |
| 67 | + errorThrown = true; |
| 68 | + errorMessage = (e as Error).message; |
| 69 | + } |
| 70 | + |
| 71 | + errorThrown.should.equal(false); |
| 72 | + errorMessage.should.not.match(/Cannot use common sdk module/); |
| 73 | + }); |
| 74 | + |
| 75 | + it(`${tokenName} should build transaction successfully`, async function () { |
| 76 | + const token = bitgo.coin(tokenName) as MonToken; |
| 77 | + // @ts-expect-error - accessing protected method for testing |
| 78 | + const builder = token.getTransactionBuilder(); |
| 79 | + |
| 80 | + // Set up a basic transfer transaction |
| 81 | + // @ts-expect-error - type expects TransactionType enum |
| 82 | + builder.type('Send'); |
| 83 | + builder.fee({ |
| 84 | + fee: '10000000000', |
| 85 | + gasLimit: '100000', |
| 86 | + }); |
| 87 | + builder.counter(1); |
| 88 | + builder.contract(token.tokenContractAddress); |
| 89 | + |
| 90 | + // Verify the builder is correctly configured |
| 91 | + builder.should.have.property('_type', 'Send'); |
| 92 | + builder.should.have.property('_fee'); |
| 93 | + builder.should.have.property('_counter', 1); |
| 94 | + }); |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + it('should verify all Mon tokens use MonToken class, not EthLikeErc20Token', function () { |
| 99 | + mainnetTokens.forEach((tokenName) => { |
| 100 | + const token = bitgo.coin(tokenName); |
| 101 | + token.should.be.instanceOf(MonToken); |
| 102 | + token.constructor.name.should.equal('MonToken'); |
| 103 | + token.constructor.name.should.not.equal('EthLikeErc20Token'); |
| 104 | + }); |
| 105 | + }); |
| 106 | + }); |
| 107 | +}); |
0 commit comments