This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
2,209 additions
and
852 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist | ||
coverage | ||
src/cli.js |
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,92 @@ | ||
|
||
/* global jest:true describe:true test:true expect:true */ | ||
|
||
import Web3 from 'web3' | ||
|
||
import { RougeProtocol } from '../src/index' | ||
|
||
import * as protocolSolidity from '../node_modules/rouge-protocol-solidity/package.json' | ||
|
||
const web3 = new Web3('https://sokol.poa.network') | ||
|
||
const rouge = RougeProtocol(web3) | ||
|
||
const issuerPkey = '0x1111111111111111111111111111111111111111111111111111111111111111' | ||
const issuerAccount = web3.eth.accounts.privateKeyToAccount(issuerPkey) | ||
|
||
const campaignAddress = '0x79fe544d081210b15bcfbb0cbd9ca12c5c11226c' | ||
const campaign = rouge.as(issuerAccount).campaign$(campaignAddress) | ||
|
||
jest.setTimeout(50000) | ||
|
||
describe('campaign.version()', () => { | ||
test( | ||
`return ${protocolSolidity.version}`, | ||
async () => expect(await campaign.version).toEqual(protocolSolidity.version) | ||
) | ||
}) | ||
|
||
describe('campaign.name()', () => { | ||
test( | ||
`return 'JEST TEST campaign'`, | ||
async () => expect(await campaign.name).toEqual('JEST TEST campaign') | ||
) | ||
}) | ||
|
||
describe('campaign.info()', () => { | ||
const expected = '0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a0001ffff000000000000000000000000000000000000000000000000000000005d2ec3854a45535420544553542063616d706169676e' // eslint-disable-line max-len | ||
test( | ||
`return ${expected}`, | ||
async () => expect(await campaign.info).toEqual(expected) | ||
) | ||
}) | ||
|
||
describe('campaign.expiration()', () => { | ||
const expected = '1563345797' | ||
test( | ||
`return ${JSON.stringify(expected)}`, | ||
async () => expect(await campaign.expiration).toEqual(expected) | ||
) | ||
}) | ||
|
||
describe('campaign.issuance()', () => { | ||
const expected = '1' | ||
test( | ||
`return ${expected}`, | ||
async () => expect(await campaign.issuance).toEqual(expected) | ||
) | ||
}) | ||
|
||
describe('campaign.state()', () => { | ||
const expected = '0x0000000101000000010000000000000000' | ||
test( | ||
`return ${expected}`, | ||
async () => expect(await campaign.state).toEqual(expected) | ||
) | ||
}) | ||
|
||
// expected to build from state | ||
|
||
describe('campaign.available()', () => { | ||
const expected = '1' | ||
test( | ||
`return ${expected}`, | ||
async () => expect(await campaign.available).toEqual(expected) | ||
) | ||
}) | ||
|
||
describe('campaign.acquired()', () => { | ||
const expected = '0' | ||
test( | ||
`return ${expected}`, | ||
async () => expect(await campaign.acquired).toEqual(expected) | ||
) | ||
}) | ||
|
||
describe('campaign.redeemed()', () => { | ||
const expected = '0' | ||
test( | ||
`return ${expected}`, | ||
async () => expect(await campaign.redeemed).toEqual(expected) | ||
) | ||
}) |
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 |
---|---|---|
@@ -1,33 +1,153 @@ | ||
|
||
/* global describe:true it:true expect: true */ | ||
/* global jest:true describe:true test:true expect:true */ | ||
|
||
import Web3 from 'web3' | ||
// import moment from 'moment' | ||
|
||
import { RougeProtocol } from '../src/index' | ||
|
||
// const issuerPkey = '0x1111111111111111111111111111111111111111111111111111111111111111' | ||
import * as solidity from '../node_modules/rouge-protocol-solidity/package.json' | ||
|
||
const rgeAddressSokol = '0x5475300766433dd082a7340fc48a445c483df68f' | ||
const currentFactory = '0x277FB7D416B6316E17954823aa621F3E321c8a72' | ||
const currentDefaultTare = '100000' | ||
|
||
// const provider = new Web3.providers.HttpProvider('https://sokol.poa.network') | ||
|
||
const web3 = new Web3('https://sokol.poa.network') | ||
|
||
const rouge = RougeProtocol({ web3 }) | ||
// TODO test on ganache | ||
// const ganache = require("ganache-core") | ||
// const web3 = new Web3(ganache.provider()) | ||
|
||
// issuer TEST addres is 0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A | ||
const issuerPkey = '0x1111111111111111111111111111111111111111111111111111111111111111' | ||
const issuerAccount = web3.eth.accounts.privateKeyToAccount(issuerPkey) | ||
const issuerMinFuel = 100 // finney | ||
const issuerMinRGE = 10 * 10 ** 6 | ||
|
||
// user TEST addres is 0x1563915e194D8CfBA1943570603F7606A3115508 | ||
const userPkey = '0x2222222222222222222222222222222222222222222222222222222222222222' | ||
const userAccount = web3.eth.accounts.privateKeyToAccount(userPkey) | ||
const userMinFuel = 10 // finney | ||
|
||
jest.setTimeout(50000) | ||
|
||
describe('Precondition tests', () => { | ||
|
||
// should have at least N ETH/POA to start the test | ||
|
||
test('enough Fuel issuer', async () => { | ||
const finney = parseInt(web3.utils.fromWei(await web3.eth.getBalance(issuerAccount.address), 'finney')) | ||
return expect(finney).toBeGreaterThan(issuerMinFuel) | ||
}) | ||
|
||
test('enough Fuel user', async () => { | ||
const finney = parseInt(web3.utils.fromWei(await web3.eth.getBalance(userAccount.address), 'finney')) | ||
return expect(finney).toBeGreaterThan(userMinFuel) | ||
}) | ||
|
||
// and N RGE | ||
|
||
test('enough RGE', async () => { | ||
const tokens = web3.utils.toBN(await rouge.RGE$.balanceOf(issuerAccount.address)).toNumber() | ||
return expect(tokens).toBeGreaterThan(issuerMinRGE) | ||
}) | ||
|
||
}) | ||
|
||
const rouge = RougeProtocol(web3) | ||
|
||
describe('RougeProtocol RGE object', () => { | ||
|
||
test('RGE$address', async () => { | ||
expect.assertions(1) | ||
return expect(await rouge.RGE$.address).toBe(rgeAddressSokol) | ||
}) | ||
|
||
test('RGE$balanceOf', async () => { | ||
expect.assertions(1) | ||
return expect(await rouge.RGE$.balanceOf('0x0101010101010101010101010101010101010101')).toEqual('0') | ||
}) | ||
|
||
}) | ||
|
||
describe('RougeProtocol factory object', () => { | ||
|
||
test('factory$address', async () => { | ||
expect.assertions(1) | ||
return expect(await rouge.factory$.address).toBe(currentFactory) | ||
}) | ||
|
||
test('factory$version', async () => { | ||
expect.assertions(1) | ||
return expect(await rouge.factory$.version).toBe(solidity.version) | ||
}) | ||
|
||
test('factory$tare', async () => { | ||
expect.assertions(1) | ||
return expect((await rouge.factory$.tare).toString()).toEqual(currentDefaultTare) | ||
}) | ||
|
||
describe('RougeProtocol', () => { | ||
}) | ||
|
||
// it('rgeAddress', async () => { | ||
// // const w3Account = web3.eth.accounts.privateKeyToAccount(issuerPkey) | ||
// const issuer = (await rouge) | ||
// // const x2 = (await rouge).as(w3Account) | ||
// }) | ||
describe('RougeProtocol account object', () => { | ||
|
||
it('rgeAddress', async () => { | ||
// const issuer = (await rouge) | ||
test('as using address', async () => { | ||
expect.assertions(1) | ||
return expect((await rouge).rgeAddress).toBe('0x5475300766433dd082a7340fc48a445c483df68f') | ||
return expect(await rouge.as(issuerAccount.address).account$.address).toEqual(issuerAccount.address) | ||
}) | ||
|
||
it('tare', async () => { | ||
test('as using private key', async () => { | ||
expect.assertions(1) | ||
return expect(await (await rouge).tare).toEqual({_hex: '0x0186a0'}) | ||
return expect(await rouge.as({ pkey: issuerPkey }).account$.address).toEqual(issuerAccount.address) | ||
}) | ||
|
||
test('as using web3 account object', async () => { | ||
expect.assertions(1) | ||
return expect(await rouge.as(issuerAccount).account$.address).toEqual(issuerAccount.address) | ||
}) | ||
|
||
}) | ||
|
||
describe('rouge.createCampaign()', () => { | ||
|
||
const campaignName = 'Jest __tests__ campaign' | ||
const campaignPromise = rouge.as(issuerAccount).createCampaign({ name: campaignName }) | ||
|
||
test('return campaign object', async () => { | ||
expect.assertions(3) | ||
await expect(campaignPromise).resolves.toHaveProperty('distributeNote') | ||
await expect(campaignPromise).resolves.toHaveProperty('acquireNote') | ||
await expect(campaignPromise).resolves.toHaveProperty('redeemNote') | ||
}) | ||
|
||
test('campaign.address', async () => { | ||
const campaign = await campaignPromise | ||
await expect(campaign.address).resolves.toMatch(/^0x[0-9a-fA-F]{40}$/) | ||
}) | ||
|
||
test('campaign.name', async () => { | ||
const campaign = await campaignPromise | ||
return expect(campaign.name).resolves.toEqual(campaignName) | ||
}) | ||
|
||
test('campaign.canDistribute', async () => { | ||
const campaign = await campaignPromise | ||
return expect(campaign.canDistribute).resolves.toEqual(true) | ||
}) | ||
|
||
test('campaign.canSignRedemption', async () => { | ||
const campaign = await campaignPromise | ||
return expect(campaign.canSignRedemption).resolves.toEqual(true) | ||
}) | ||
|
||
test('campaign.distributeNote()', async () => { | ||
const campaign = await campaignPromise | ||
expect.assertions(3) | ||
await expect(campaign.acquired).resolves.toEqual('0') | ||
await expect(campaign.distributeNote(userAccount.address)).resolves.toHaveProperty('blockHash') | ||
await expect(campaign.acquired).resolves.toEqual('1') | ||
}) | ||
|
||
}) |
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,31 @@ | ||
|
||
import Web3 from 'web3' | ||
import moment from 'moment' | ||
|
||
import { RougeProtocol } from '../src/index' | ||
|
||
const web3 = new Web3('https://sokol.poa.network') | ||
|
||
const issuer = web3.eth.accounts.privateKeyToAccount('0xaaaa'.padEnd(66,'0')) | ||
|
||
const user1 = web3.eth.accounts.privateKeyToAccount('0x1111'.padEnd(66,'0')) | ||
const user2 = web3.eth.accounts.privateKeyToAccount('0x2222'.padEnd(66,'0')) | ||
const user3 = web3.eth.accounts.privateKeyToAccount('0x3333'.padEnd(66,'0')) | ||
|
||
const rouge = RougeProtocol(web3) | ||
|
||
const run = async () => { | ||
|
||
const campaign = await rouge.as(issuer).createCampaign({ | ||
name: 'Simple demo Rouge campaign', | ||
issuance: 10, | ||
expiration: moment().add(moment.duration(2, 'days')).format('X') | ||
// precheck: true | ||
}) | ||
|
||
console.log(campaign) | ||
|
||
|
||
} | ||
|
||
run() |
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
Oops, something went wrong.