First commit
This commit is contained in:
1
test/.git-folder-keeper
Normal file
1
test/.git-folder-keeper
Normal file
@@ -0,0 +1 @@
|
||||
This is a placeholder file to ensure the parent directory in the git repository. Feel free to remove.
|
41
test/SargaTrxUsdPrice.test.js
Normal file
41
test/SargaTrxUsdPrice.test.js
Normal file
@@ -0,0 +1,41 @@
|
||||
// test/SargaTrxUsdPrice.test.js
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
const TronWeb = require('tronweb')
|
||||
const HttpProvider = TronWeb.providers.HttpProvider
|
||||
const API_URL = process.env.TRON_API
|
||||
const fullNode = new HttpProvider(API_URL)
|
||||
const solidityNode = new HttpProvider(API_URL)
|
||||
const eventServer = API_URL
|
||||
const tronWeb = new TronWeb(fullNode, solidityNode, eventServer)
|
||||
|
||||
let assert
|
||||
|
||||
const SargaTrxUsdPrice = artifacts.require('SargaTrxUsdPrice')
|
||||
|
||||
contract('SargaTrxUsdPrice', () => {
|
||||
it('get TRX/USD value', async () => {
|
||||
// carga Chai como ESM y extrae assert
|
||||
const chaiModule = await import('chai')
|
||||
assert = chaiModule.assert
|
||||
|
||||
// 1) Load already deployed contract
|
||||
const distributor = await SargaTrxUsdPrice.at(process.env.CONTRACT_ADDRESS)
|
||||
|
||||
// 2) Call the getTrxUsdPrice function
|
||||
const trxUsdPrice = await distributor.getLatestPrice().call()
|
||||
console.log(
|
||||
'TRX/USD price:',
|
||||
parseFloat(trxUsdPrice.toString()) / 10 ** 8,
|
||||
'USD'
|
||||
)
|
||||
|
||||
// 3) Assert the value is greater than 0
|
||||
assert.isAbove(
|
||||
parseFloat(trxUsdPrice),
|
||||
0,
|
||||
'TRX/USD price should be greater than 0'
|
||||
)
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user