Files
SargaTrxUsdPrice/test/SargaTrxUsdPrice.test.js
2025-05-13 19:41:33 +02:00

42 lines
1.1 KiB
JavaScript

// 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'
)
})
})