일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 머신러닝기초
- 러스트 기초
- 프록시배포구조
- ethers websocket
- chainlink 설명
- ethers v6
- 스마트 컨트렉트 함수이름 중복
- 스마트컨트렉트프록시
- 체인의정석
- ethers type
- rust 기초
- 컨트렉트 동일한 함수이름 호출
- SBT표준
- ethers typescript
- 스마트컨트렉트 예약어 함수이름 중복
- nest.js설명
- 컨트렉트 배포 자동화
- git rebase
- 스마트컨트렉트 함수이름 중복 호출
- Vue.js
- 스마트컨트렉트테스트
- 깃허브명령어
- 러스트기초
- Vue
- multicall
- 러스트 기초 학습
- ambiguous function description
- vue기초
- nestjs 튜토리얼
- ethers
Archives
- Today
- Total
체인의정석
스마트컨트렉트 테스트에 Infinite Approve 적용하기 본문
728x90
반응형
먼저 approve를 무한대로 해주는 infiniteApprove의 경우
해당 글에서 힌트를 얻을 수 있었다.
decimal = 18;
const infiniteVal: number = 2 ** 256 - 1;
const infiniteValBN: BigNumber = BigNumber.from(infiniteVal);
const bigIntTest: BigNumber = ethers.utils.parseUnits(
infiniteValBN.toString(),
decimal
);
그 결과 이런식으로 한번 테스트를 해봤는데 결과는
reason: 'overflow',
code: 'NUMERIC_FAULT',
fault: 'overflow',
operation: 'BigNumber.from',
value: 1.157920892373162e+77
이렇게 나왔다.
보니까 web3 에선 위와 같이 되는것 같다.
https://github.com/ethers-io/ethers.js/discussions/2814
보니까 bigNumber가 에러가 나는 것이므로 이때는 quote를 쓰라고 한다.
하지만 값 자체가 숫자형태로 안나오기 때문에 조금 더 찾아봤다.
https://forum.openzeppelin.com/t/using-the-maximum-integer-in-solidity/3000
오픈제플린 포럼에서 서치한 결과
const bigIntTest: BigNumber = ethers.utils.parseUnits(
"115792089237316195423570985008687907853269984665640564039457584007913129639935",
0
);
console.log("bigTest >>>", bigIntTest);
이렇게 하면 bignumber를 구할 수 있었다.
const bigIntTest: BigNumber = ethers.utils.parseUnits(
"115792089237316195423570985008687907853269984665640564039457584007913129639935",
0
);
it("test inifinite approve", async function () {
await erc20Token
.approve(ExampleContract.address, bigIntTest);
expect(
await erc20Token.allowance(userA.address, ExampleContract.address)
).equal(bigIntTest);
console.log("approve num", bigIntTest);
});
위와 같이 테스트 코드를 수정하니 infinite approve가 적용되었다.
어차피 고정값으로 넣으니 overflow가 나지 않게 처음부터 고정값으로 넣고 그 상태 그대로 bigNumber로 만들어서 입력값과 결과값체크에 사용하면 되는거엿다.
728x90
반응형
'블록체인 > Solidity' 카테고리의 다른 글
payable 사용시 발생하는 에러 ParserError: Expected primary expression. (0) | 2022.08.11 |
---|---|
Solidity) 스마트컨트렉트에서 이더리움을 보내는 방법 (0) | 2022.08.10 |
스마트컨트렉트에서 소수점 처리하는법과 엑셀에서 검산하는 방법 및 유의점 (0) | 2022.07.25 |
Solidity 0.8.0 버전에서 HashStruct안에 UUID 넣는 법 (0) | 2022.07.21 |
Solidity에서 자주 만나는 에러 "CompilerError: Stack too deep, try removing local variables." 그리고 에러에 대한 해결 방안 정리 , 이벤트 로그와 함수 입력값 구조체로 개수 줄이기 (0) | 2022.07.13 |
Comments