Skip to content

Commit

Permalink
fixes and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brtkx committed Jul 17, 2024
1 parent c3bb004 commit 31c5355
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
11 changes: 10 additions & 1 deletion tests/integration/l1l3Bridger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,16 @@ describe('L1 to L3 Bridging', () => {
await testHappyPathNonFeeOrStandard(depositParams)
})

itOnlyWhenCustomGasToken('happy path OnlyCustomFee', async () => {
itOnlyWhenCustomGasToken('happy path OnlyCustomFee', async function () {
const decimals = await getNativeTokenDecimals({
l1Provider: l1Signer.provider!,
l2Network: l3Network,
})

if (decimals !== 18) {
this.skip()
}

const l3Recipient = ethers.utils.hexlify(ethers.utils.randomBytes(20))
const l1FeeToken = (await l1l3Bridger.getGasTokenOnL1(
l1Signer.provider!,
Expand Down
31 changes: 30 additions & 1 deletion tests/unit/nativeToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { expect } from 'chai'

import { BigNumber } from 'ethers'
import { parseEther } from 'ethers/lib/utils'
import { scaleToNativeTokenDecimals } from '../../src/lib/utils/lib'
import {
nativeTokenDecimalsTo18Decimals,
scaleToNativeTokenDecimals,
} from '../../src/lib/utils/lib'

const AMOUNT_TO_SCALE = parseEther('1.23456789')

Expand Down Expand Up @@ -79,4 +82,30 @@ describe('Native token', () => {
decimalsToError(24)
).to.be.true
})

it('scales native token decimals to 18 decimals', () => {
expect(
nativeTokenDecimalsTo18Decimals({
amount: BigNumber.from('1.2345'),
decimals: 16,
}).eq(BigNumber.from('123.45')),
decimalsToError(16)
).to.be.true

expect(
nativeTokenDecimalsTo18Decimals({
amount: BigNumber.from('1.2345'),
decimals: 18,
}).eq(BigNumber.from('1.2345')),
decimalsToError(18)
).to.be.true

expect(
nativeTokenDecimalsTo18Decimals({
amount: BigNumber.from('1.2345'),
decimals: 20,
}).eq(BigNumber.from('0.012345')),
decimalsToError(20)
).to.be.true
})
})

0 comments on commit 31c5355

Please sign in to comment.