|
| 1 | +/* |
| 2 | +This file is part of web3.js. |
| 3 | +
|
| 4 | +web3.js is free software: you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU Lesser General Public License as published by |
| 6 | +the Free Software Foundation, either version 3 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +
|
| 9 | +web3.js is distributed in the hope that it will be useful, |
| 10 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +GNU Lesser General Public License for more details. |
| 13 | +
|
| 14 | +You should have received a copy of the GNU Lesser General Public License |
| 15 | +along with web3.js. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +*/ |
| 17 | + |
| 18 | +import { ETH_DATA_FORMAT } from 'web3-types'; |
| 19 | +import { Contract } from '../../src'; |
| 20 | +import { getSystemTestProvider, createTempAccount } from '../fixtures/system_test_utils'; |
| 21 | + |
| 22 | +describe('contract', () => { |
| 23 | + // Create a new contract object using the ABI and bytecode |
| 24 | + const abi = [ |
| 25 | + { |
| 26 | + inputs: [{ internalType: 'uint256', name: '_myNumber', type: 'uint256' }], |
| 27 | + stateMutability: 'nonpayable', |
| 28 | + type: 'constructor', |
| 29 | + }, |
| 30 | + { |
| 31 | + inputs: [], |
| 32 | + name: 'myNumber', |
| 33 | + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], |
| 34 | + stateMutability: 'view', |
| 35 | + type: 'function', |
| 36 | + }, |
| 37 | + { |
| 38 | + inputs: [{ internalType: 'uint256', name: '_myNumber', type: 'uint256' }], |
| 39 | + name: 'setMyNumber', |
| 40 | + outputs: [], |
| 41 | + stateMutability: 'nonpayable', |
| 42 | + type: 'function', |
| 43 | + }, |
| 44 | + ]; |
| 45 | + let acc: { address: string; privateKey: string }; |
| 46 | + let contract: Contract<typeof abi>; |
| 47 | + |
| 48 | + beforeEach(async () => { |
| 49 | + acc = await createTempAccount(); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should be able to add `data` input without `0x` prefix', async () => { |
| 53 | + contract = new Contract(abi, undefined, { |
| 54 | + provider: getSystemTestProvider(), |
| 55 | + }); |
| 56 | + |
| 57 | + const myContract = contract.deploy({ |
| 58 | + data: '608060405234801561001057600080fd5b506040516101d93803806101d983398181016040528101906100329190610054565b806000819055505061009e565b60008151905061004e81610087565b92915050565b60006020828403121561006657600080fd5b60006100748482850161003f565b91505092915050565b6000819050919050565b6100908161007d565b811461009b57600080fd5b50565b61012c806100ad6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806323fd0e401460375780636ffd773c146051575b600080fd5b603d6069565b6040516048919060bf565b60405180910390f35b6067600480360381019060639190608c565b606f565b005b60005481565b8060008190555050565b60008135905060868160e2565b92915050565b600060208284031215609d57600080fd5b600060a9848285016079565b91505092915050565b60b98160d8565b82525050565b600060208201905060d2600083018460b2565b92915050565b6000819050919050565b60e98160d8565b811460f357600080fd5b5056fea2646970667358221220d28cf161457f7936995800eb9896635a02a559a0561bff6a09a40bfb81cd056564736f6c63430008000033', |
| 59 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 60 | + // @ts-expect-error |
| 61 | + arguments: [1], |
| 62 | + }); |
| 63 | + |
| 64 | + const gas = await myContract.estimateGas( |
| 65 | + { |
| 66 | + from: acc.address, |
| 67 | + }, |
| 68 | + ETH_DATA_FORMAT, |
| 69 | + ); |
| 70 | + expect(gas).toBeDefined(); |
| 71 | + expect(gas).toMatch(/0[xX][0-9a-fA-F]/i); |
| 72 | + }); |
| 73 | +}); |
0 commit comments