Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add appointOracle RPC #336

Merged
merged 7 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,26 @@ describe('Oracle', () => {
{ currency: 'EUR', token: 'APPLE' }
]

const data = await client.oracle.appointOracle(await container.getNewAddress(), priceFeeds, { weightage: 1 })
const txid = await client.oracle.appointOracle(await container.getNewAddress(), priceFeeds, { weightage: 1 })

expect(typeof data).toStrictEqual('string')
expect(data.length).toStrictEqual(64)
expect(typeof txid).toStrictEqual('string')
expect(txid.length).toStrictEqual(64)

await container.generate(1)
jingyi2811 marked this conversation as resolved.
Show resolved Hide resolved

const result = await container.call('getoracledata', [txid])
expect(result).toStrictEqual(
{
weightage: 1,
oracleid: txid,
address: expect.any(String), // This is an oracle address, not the address in line 26
monstrobishi marked this conversation as resolved.
Show resolved Hide resolved
priceFeeds: [
{ token: 'APPLE', currency: 'EUR' },
{ token: 'TESLA', currency: 'USD' }
],
tokenPrices: []
}
)
})

it('should appointOracle with utxos', async () => {
Expand All @@ -44,10 +60,26 @@ describe('Oracle', () => {
}
})

const data = await client.oracle.appointOracle(address, priceFeeds, { weightage: 1, utxos: inputs })
const txid = await client.oracle.appointOracle(address, priceFeeds, { weightage: 1, utxos: inputs })

expect(typeof data).toStrictEqual('string')
expect(data.length).toStrictEqual(64)
expect(typeof txid).toStrictEqual('string')
expect(txid.length).toStrictEqual(64)

await container.generate(1)

const result = await container.call('getoracledata', [txid])
expect(result).toStrictEqual(
{
weightage: 1,
oracleid: txid,
address: expect.any(String), // This is an oracle address, not the address in line 54
priceFeeds: [
{ token: 'APPLE', currency: 'EUR' },
{ token: 'TESLA', currency: 'USD' }
],
tokenPrices: []
}
)
})

it('should not appointOracle with arbitrary utxos', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jellyfish-api-core/src/category/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Oracle {
}

/**
* Creates an oracle appointment transaction and saves it to the database.
* Creates a price oracle for rely of real time price data.
*
* @param {string} address
* @param {PriceFeed[]} priceFeeds
Expand Down
2 changes: 1 addition & 1 deletion website/docs/jellyfish/api/oracle.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const something = await client.oracle.method()

## appointOracle

Creates an oracle appointment transaction and saves it to the database.
Creates a price oracle for rely of real time price data.

```ts title="client.oracle.appointOracle()"
interface oracle {
Expand Down