-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45b1822
commit 7c63eb8
Showing
12 changed files
with
99 additions
and
586 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,26 @@ | ||
import chai from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
import { | ||
calculateGasLimit, | ||
calculateMaximumGas, | ||
deserializeTransactionGasDetails, | ||
serializeTransactionGasDetails, | ||
} from '../gas'; | ||
import { decimalStringToHexString, decimalToHexString } from '../format'; | ||
import { | ||
EVMGasType, | ||
TransactionGasDetails, | ||
TransactionGasDetailsSerialized, | ||
} from '../../models/response-types'; | ||
import { calculateGasLimit, calculateMaximumGas } from '../gas'; | ||
import { EVMGasType, TransactionGasDetails } from '../../models/response-types'; | ||
|
||
chai.use(chaiAsPromised); | ||
const { expect } = chai; | ||
|
||
describe('gas', () => { | ||
it('Should calculate gas limit correctly', () => { | ||
const gasEstimate = BigNumber.from('100000'); | ||
const gasLimitString = calculateGasLimit(gasEstimate).toHexString(); | ||
expect(gasLimitString).to.equal(decimalStringToHexString('120000')); | ||
const gasEstimate = BigInt('100000'); | ||
const gasLimit = calculateGasLimit(gasEstimate); | ||
expect(Number(gasLimit)).to.equal(120000); | ||
}); | ||
|
||
it('Should calculate maximum gas correctly', () => { | ||
const gasDetails: TransactionGasDetails = { | ||
evmGasType: EVMGasType.Type2, | ||
gasEstimate: BigNumber.from('100000'), | ||
maxFeePerGas: BigNumber.from('20000'), | ||
maxPriorityFeePerGas: BigNumber.from('500'), | ||
gasEstimate: BigInt('100000'), | ||
maxFeePerGas: BigInt('20000'), | ||
maxPriorityFeePerGas: BigInt('500'), | ||
}; | ||
const gasLimitString = calculateMaximumGas(gasDetails).toHexString(); | ||
expect(gasLimitString).to.equal(decimalStringToHexString('2400000000')); | ||
}); | ||
|
||
it('Should serialize tx gas details', () => { | ||
const gasDetails: TransactionGasDetails = { | ||
evmGasType: EVMGasType.Type2, | ||
gasEstimate: BigNumber.from('10'), | ||
maxFeePerGas: BigNumber.from('20'), | ||
maxPriorityFeePerGas: BigNumber.from('1'), | ||
}; | ||
const serialized = serializeTransactionGasDetails(gasDetails); | ||
const expectedSerialized: TransactionGasDetailsSerialized = { | ||
evmGasType: EVMGasType.Type2, | ||
gasEstimateString: decimalToHexString(10), | ||
maxFeePerGasString: decimalToHexString(20), | ||
maxPriorityFeePerGasString: decimalToHexString(1), | ||
}; | ||
expect(serialized).to.deep.equal(expectedSerialized); | ||
expect(deserializeTransactionGasDetails(serialized)).to.deep.equal( | ||
gasDetails, | ||
); | ||
const gasLimit = calculateMaximumGas(gasDetails); | ||
expect(gasLimit.toString()).to.equal('2400000000'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
|
||
export const decimalStringToHexString = (dec: string) => { | ||
return BigNumber.from(dec).toHexString(); | ||
}; | ||
|
||
export const decimalToHexString = (dec: number) => { | ||
return BigNumber.from(dec).toHexString(); | ||
export const decimalToHexString = (dec: string | number) => { | ||
return BigInt(dec).toString(16); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.