protocol/contracts/test-utils/test/transaction_hash.ts
Elena 4d9b68d527
Removes references to tslint (#619)
* Removes references to tslint in contract-wrappers
which are obsoleted since https://github.com/0xProject/protocol/pull/584

* Remove tslint references in contracts/utils and test utils
obsoleted by https://github.com/0xProject/protocol/pull/589

* Remove tslint references in contracts/zeroex and test utils
obsoleted by https://github.com/0xProject/protocol/pull/587

* Remove other obsoleted tslint references

* Update contributing guidelines with eslint

* Fix prettier errors
2022-11-19 17:52:00 +02:00

48 lines
1.9 KiB
TypeScript

import { chaiSetup } from '@0x/dev-utils';
import { ZeroExTransaction } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import 'mocha';
import { transactionHashUtils } from '../src';
import { constants } from '../src/constants';
chaiSetup.configure();
const expect = chai.expect;
describe('0x transaction hashing', () => {
describe('#getTransactionHashHex', () => {
const expectedTransactionHash = '0x7845d260300acfbebaff52f0462f984016473290b9eb865fb6ffac0503cab364';
const fakeVerifyingContractAddress = '0x5e72914535f202659083db3a02c984188fa26e9f';
const fakeChainId = 1337;
const transaction: ZeroExTransaction = {
signerAddress: constants.NULL_ADDRESS,
salt: new BigNumber(0),
expirationTimeSeconds: new BigNumber(0),
gasPrice: new BigNumber(0),
data: constants.NULL_BYTES,
domain: {
verifyingContract: fakeVerifyingContractAddress,
chainId: fakeChainId,
},
};
it('calculates the transaction hash', async () => {
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
expect(transactionHash).to.be.equal(expectedTransactionHash);
});
it('calculates the transaction hash if amounts are strings', async () => {
// It's common for developers using javascript to provide the amounts
// as strings. Since we eventually toString() the BigNumber
// before encoding we should result in the same orderHash in this scenario
const transactionHash = transactionHashUtils.getTransactionHashHex({
...transaction,
salt: '0',
expirationTimeSeconds: '0',
gasPrice: '0',
} as any);
expect(transactionHash).to.be.equal(expectedTransactionHash);
});
});
});