-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from yanyanho/main
add test
- Loading branch information
Showing
5 changed files
with
251 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.dl.officialsite; | ||
|
||
import com.dl.officialsite.aave.AaveService; | ||
import com.dl.officialsite.contract.ilendingpool.ILendingPool; | ||
import com.dl.officialsite.contract.ilendingpooladdressesprovider.ILendingPoolAddressesProvider; | ||
import com.dl.officialsite.contract.ipool.IPool; | ||
import com.dl.officialsite.contract.ipooladdressesprovider.IPoolAddressesProvider; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.web3j.crypto.Credentials; | ||
import org.web3j.protocol.Web3j; | ||
import org.web3j.protocol.http.HttpService; | ||
import org.web3j.tuples.Tuple; | ||
import org.web3j.tuples.generated.Tuple6; | ||
import org.web3j.tx.gas.ContractGasProvider; | ||
import org.web3j.tx.gas.StaticGasProvider; | ||
|
||
import java.math.BigInteger; | ||
|
||
import static org.web3j.tx.gas.DefaultGasProvider.GAS_LIMIT; | ||
import static org.web3j.tx.gas.DefaultGasProvider.GAS_PRICE; | ||
|
||
public class AaveTest { | ||
|
||
public static ContractGasProvider GAS_PROVIDER = new StaticGasProvider(GAS_PRICE, GAS_LIMIT); | ||
public static final Logger logger = LoggerFactory.getLogger(AaveTest.class); | ||
|
||
BigInteger e16 = new BigInteger("10000000000000000"); | ||
BigInteger e8 = new BigInteger("100000000"); | ||
BigInteger e23 = new BigInteger("100000000000000000000000"); | ||
|
||
Web3j web3j = Web3j.build(new HttpService("https://polygon-rpc.com")); | ||
String whale = "0xEf53a1797Df32c238F46f1037C8a30Ac884E178C"; | ||
|
||
public Credentials getCredentials() { | ||
return Credentials.create("1"); | ||
} | ||
|
||
|
||
|
||
|
||
@Test | ||
public void getHFV3() throws Exception { | ||
|
||
// polygonv3 | ||
String lendingPoolAddressProviderV3 = "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb"; | ||
IPoolAddressesProvider addrProV3 = IPoolAddressesProvider.load(lendingPoolAddressProviderV3, web3j, getCredentials(), GAS_PROVIDER); | ||
String s = addrProV3.getPool().send(); | ||
logger.info("v3 pool: " + s); | ||
|
||
IPool lendingPoolv3 = IPool.load(s, web3j, getCredentials(), GAS_PROVIDER); | ||
Tuple6<BigInteger, BigInteger, BigInteger, BigInteger, BigInteger, BigInteger> accountData = lendingPoolv3.getUserAccountData(whale).send(); | ||
logger.info("Restult:" + accountData.toString()); | ||
BigInteger supply = accountData.getValue1().divide(e8); | ||
BigInteger borrow = accountData.getValue2().divide(e8); | ||
|
||
|
||
BigInteger LTV = accountData.getValue5().divide(BigInteger.valueOf(100)); | ||
|
||
BigInteger hf1 = accountData.getValue6(); | ||
logger.info("*******hf: " + hf1.divide(e16).floatValue() / 100); | ||
logger.info("*******borrow: " + borrow); | ||
logger.info("*******supply: " + supply); | ||
logger.info("LTV:" + LTV + "%" ); | ||
|
||
|
||
// get Interest | ||
String usdc= "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"; | ||
String dai= "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063"; | ||
|
||
IPool.ReserveData reserveData = lendingPoolv3.getReserveData(usdc).send(); | ||
|
||
logger.info( "USDC variable deposit interest: " + reserveData.currentLiquidityRate.divide(e23).floatValue()/100) ; | ||
logger.info( "USDC variable borrow interest: " + reserveData.currentVariableBorrowRate.divide(e23).floatValue()/100) ; | ||
|
||
reserveData = lendingPoolv3.getReserveData(dai).send(); | ||
logger.info( "DAI variable deposit interest: " + reserveData.currentLiquidityRate.divide(e23).floatValue()/100) ; | ||
logger.info( "DAI variable borrow interest: " + reserveData.currentVariableBorrowRate.divide(e23).floatValue()/100) ; | ||
} | ||
|
||
|
||
@Test | ||
public void getHFV2() throws Exception { | ||
//polygon V2 | ||
String lendingPoolAddressProviderV2 = "0xd05e3E715d945B59290df0ae8eF85c1BdB684744"; | ||
ILendingPoolAddressesProvider addrPro = ILendingPoolAddressesProvider.load(lendingPoolAddressProviderV2, web3j, getCredentials(), GAS_PROVIDER); | ||
logger.info("addrPro:" + addrPro.getContractAddress()); | ||
String lendingPoolAddress = addrPro.getLendingPool().send(); | ||
ILendingPool lendingPool = ILendingPool.load(lendingPoolAddress, web3j, getCredentials(), GAS_PROVIDER); | ||
BigInteger hf = lendingPool.getUserAccountData(whale).send().getValue6(); | ||
logger.info("*******hf: " + hf.divide(e16).floatValue() / 100); | ||
//todo the same logic | ||
|
||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/java/com/dl/officialsite/OfficialSiteApplicationTests.java
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.dl.officialsite; | ||
|
||
import com.dl.officialsite.mail.EmailService; | ||
import com.dl.officialsite.member.MemberController; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class OfficialSiteApplicationTests { | ||
public static final Logger logger = LoggerFactory.getLogger(MemberController.class); | ||
|
||
@Autowired | ||
EmailService emailService; | ||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
|
||
|
||
@Test | ||
public void mailTest() { | ||
|
||
//Get the mailer instance | ||
|
||
|
||
//Send a composed mail | ||
emailService.sendSimpleMessage("[email protected]", "Test Subject1", "Testing body11"); | ||
|
||
//Send a pre-configured mail | ||
//emailService.sendPreConfiguredMail("Exception occurred everywhere.. where are you ????"); | ||
} | ||
|
||
|
||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.dl.officialsite; | ||
|
||
import com.dl.officialsite.common.base.BaseResponse; | ||
import com.dl.officialsite.member.MemberController; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.web3j.crypto.Keys; | ||
import org.web3j.crypto.Sign; | ||
|
||
import java.math.BigInteger; | ||
import java.security.SignatureException; | ||
|
||
import static org.web3j.crypto.Sign.getEthereumMessageHash; | ||
import static org.web3j.utils.Numeric.hexStringToByteArray; | ||
|
||
|
||
class UtilTests { | ||
public static final Logger logger = LoggerFactory.getLogger(MemberController.class); | ||
|
||
|
||
@Test | ||
public void checkSignature() throws SignatureException { | ||
// SignInfo sign = new SignInfo("0x2fE023204958fc4c44f639CE72D3bdC0f025Adfe",new BigInteger("1c",16) | ||
// , new BigInteger("0ea7d9596f0c90d2cf417a079c6c56ef10dda520cf392e89ae5a7bdc1d09c8db",16) | ||
// ,new BigInteger("037f66fde24749ba842ef5de24902451f0fe9baf5cd1b0b9dca42c71baaf98b0",16),"hello"); | ||
// byte[] v = new byte[] {(byte) sign.getV()}; | ||
// byte[] r = Numeric.toBytesPadded(sign.getR(), 32); | ||
// byte[] s = Numeric.toBytesPadded(sign.getS(), 32); | ||
// Sign.SignatureData signatureData = new Sign.SignatureData(v,r ,s ); | ||
// BigInteger publicKey = Sign.signedMessageHashToKey(getEthereumMessageHash(sign.getMessage().getBytes()), signatureData); | ||
// String address = Keys.getAddress(publicKey); | ||
// logger.info("*******"+address); | ||
|
||
} | ||
|
||
|
||
@Test | ||
public void checkSignature1() throws SignatureException { | ||
String message = "localhost:3000 wants you to sign in with your Ethereum account:\n" + | ||
"0x2fE023204958fc4c44f639CE72D3bdC0f025Adfe\n" + | ||
"\n" + | ||
"Sign in with Etherem to Dapp-Learning\n" + | ||
"\n" + | ||
"URI: http://localhost:3000\n" + | ||
"Version: 1\n" + | ||
"Chain ID: 1\n" + | ||
"Nonce: ABA490FDFFF5742158889682D9308F1AF\n" + | ||
"Issued At: 2023-10-15T15:35:00.404Z"; | ||
|
||
|
||
|
||
byte[] v1 = hexStringToByteArray("0x1b"); | ||
byte[] r1 = hexStringToByteArray("0x64d251ade78cf78ad3f1b1115421f6ac97eff32c8c2b8404db6484bc3d6fe67f"); | ||
byte[] s1 = hexStringToByteArray("0x2afeb45431847f3fa513921542a18727ec72413b05a8c6c3a39323d4e4095f16"); | ||
Sign.SignatureData signatureData1 = new Sign.SignatureData(v1,r1 ,s1); | ||
BigInteger publicKey1 = Sign.signedMessageHashToKey(getEthereumMessageHash(message.getBytes()), signatureData1); | ||
String address1 = Keys.getAddress(publicKey1); | ||
|
||
logger.info("*******" + address1 + "*******"); | ||
|
||
|
||
|
||
} | ||
|
||
|
||
@Test | ||
public void checkNonce() throws SignatureException { | ||
String message = "localhost:3000 wants you to sign in with your Ethereum account:\n" + | ||
"0x2fE023204958fc4c44f639CE72D3bdC0f025Adfe\n" + | ||
"\n" + | ||
"Sign in with Etherem to Dapp-Learning\n" + | ||
"\n" + | ||
"URI: http://localhost:3000\n" + | ||
"Version: 1\n" + | ||
"Chain ID: 1\n" + | ||
"Nonce: ABA490FDFFF5742158889682D9308F1AF\n" + | ||
"Issued At: 2023-10-15T15:35:00.404Z"; | ||
|
||
|
||
//JSONObject obj = new JSONObject(message); | ||
int index = message.indexOf("Nonce:"); | ||
String nonce = message.substring(index+7, index+39); | ||
|
||
|
||
|
||
logger.info("*******" + nonce + "*******"); | ||
|
||
} | ||
|
||
|
||
|
||
@Test | ||
public void objectToJson() throws JsonProcessingException { | ||
|
||
|
||
BaseResponse baseResponse = BaseResponse.failWithReason("2001", "please login in"); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
String s = objectMapper.writeValueAsString( baseResponse ); | ||
|
||
logger.info("*******" + s + "*******"); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
} |