-
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
1 parent
1a94931
commit 35c6dcd
Showing
5 changed files
with
218 additions
and
21 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 |
---|---|---|
@@ -1,2 +1,19 @@ | ||
#V2 | ||
(contract-call? .keys set-protocol-fee-percent u5) | ||
::help | ||
::set_tx_sender ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM | ||
(contract-call? .keys set-protocol-fee-destination ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5) | ||
(contract-call? .keys set-protocol-fee-destination 'ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5) | ||
::set_tx_sender ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG | ||
(contract-call? .keys get-protocol-fee-destination) | ||
(contract-call? .keys get-protocol-fee-destination tx-sender) | ||
(contract-call? .keys get-protocol-fee-destination) | ||
::set_tx_sender ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM | ||
(contract-call? .keys get-protocol-fee-destination) | ||
::functions | ||
::set_tx_sender ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG | ||
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.keys get-protocol-fee-destination) | ||
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.keys get-protocol-fee-destination tx-sender) | ||
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.keys get-protocol-destination tx-sender) | ||
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.keys get-protocol-destination) | ||
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.keys get-owner) |
This file was deleted.
Oops, something went wrong.
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,23 +1,171 @@ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { Cl } from '@stacks/transactions'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { initSimnet } from '@hirosystems/clarinet-sdk'; | ||
const simnet = await initSimnet(); | ||
|
||
const accounts = simnet.getAccounts(); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const address1 = accounts.get('wallet_1')!; | ||
const deployer = accounts.get('deployer')!; | ||
const protocolFessDestination = accounts.get('wallet_1')!; | ||
const address2 = accounts.get('wallet_2')!; | ||
const address3 = accounts.get('wallet_3')!; | ||
|
||
describe('test `get-price` public function', () => { | ||
it('should get price of key', () => { | ||
describe('Should initialise keys contract', () => { | ||
it('only contract owner can set protocol fee destination', () => { | ||
const setProtocolFeeDestination = simnet.callPublicFn( | ||
'keys', | ||
'set-protocol-fee-destination', | ||
[Cl.standardPrincipal(protocolFessDestination)], | ||
address2 | ||
); | ||
|
||
//@ts-ignore | ||
expect(setProtocolFeeDestination.result).toBeErr(Cl.uint(401)); | ||
}); | ||
|
||
it('should set protocol fee destination', () => { | ||
const setProtocolFeeDestination = simnet.callPublicFn( | ||
'keys', | ||
'set-protocol-fee-destination', | ||
[Cl.standardPrincipal(protocolFessDestination)], | ||
deployer | ||
); | ||
|
||
//@ts-ignore | ||
expect(setProtocolFeeDestination.result).toBeOk(Cl.bool(true)); | ||
|
||
const getProtocolDestinationResponse = simnet.callReadOnlyFn( | ||
'keys', | ||
'get-protocol-fee-destination', | ||
[], | ||
address2 | ||
); | ||
|
||
//@ts-ignore | ||
expect(getProtocolDestinationResponse.result).toBeOk( | ||
Cl.standardPrincipal(protocolFessDestination) | ||
); | ||
}); | ||
|
||
it('should set protocol fee percent', () => { | ||
const setProtocolFeePercent = simnet.callPublicFn( | ||
'keys', | ||
'set-protocol-fee-percent', | ||
[Cl.uint(10)], | ||
deployer | ||
); | ||
|
||
//@ts-ignore | ||
expect(setProtocolFeePercent.result).toBeOk(Cl.bool(true)); | ||
|
||
const getProtocolFeePercentResponse = simnet.callReadOnlyFn( | ||
'keys', | ||
'get-protocol-fee-percent', | ||
[], | ||
address2 | ||
); | ||
|
||
//@ts-ignore | ||
expect(getProtocolFeePercentResponse.result).toBeOk(Cl.uint(10)); | ||
}); | ||
|
||
it('should set subject fee percent', () => { | ||
const setSubjectFeePercent = simnet.callPublicFn( | ||
'keys', | ||
'set-subject-fee-percent', | ||
[Cl.uint(10)], | ||
deployer | ||
); | ||
|
||
//@ts-ignore | ||
expect(setSubjectFeePercent.result).toBeOk(Cl.bool(true)); | ||
|
||
const getSubjectFeeResponse = simnet.callReadOnlyFn( | ||
'keys', | ||
'get-subject-fee-percent', | ||
[], | ||
address2 | ||
); | ||
|
||
//@ts-ignore | ||
expect(getSubjectFeeResponse.result).toBeOk(Cl.uint(10)); | ||
}); | ||
}); | ||
|
||
describe('Core trade functionality', () => { | ||
it('should get price for supply 1 and amount 2', () => { | ||
const getPriceResponse = simnet.callReadOnlyFn( | ||
'keys', | ||
'get-price', | ||
[Cl.uint(1), Cl.uint(2)], | ||
address2 | ||
); | ||
|
||
console.log(Cl.prettyPrint(getPriceResponse.result)); | ||
//@ts-ignore | ||
expect(getPriceResponse.result).toBeUint(312500000000000); | ||
}); | ||
|
||
it('should get price for supply 2 and amount 6', () => { | ||
const getPriceResponse = simnet.callReadOnlyFn( | ||
'keys', | ||
'get-price', | ||
[Cl.uint(2), Cl.uint(6)], | ||
address2 | ||
); | ||
|
||
console.log(Cl.prettyPrint(getPriceResponse.result)); | ||
//@ts-ignore | ||
expect(getPriceResponse.result).toBeUint(8687500000000000); | ||
}); | ||
|
||
it('should get price for supply 0 and amount 1', () => { | ||
const getPriceResponse = simnet.callReadOnlyFn( | ||
'keys', | ||
'get-price', | ||
[Cl.uint(0), Cl.uint(100)], | ||
address1 | ||
[Cl.uint(0), Cl.uint(1)], | ||
address2 | ||
); | ||
|
||
console.log(Cl.prettyPrint(getPriceResponse.result)); | ||
//@ts-ignore | ||
expect(getPriceResponse.result).toBeUint(0); | ||
}); | ||
|
||
it('test Tx', () => { | ||
const txResponse = simnet.callPublicFn( | ||
'hello-world', | ||
'pay', | ||
[Cl.standardPrincipal(address3)], | ||
address2 | ||
); | ||
|
||
console.log(Cl.prettyPrint(txResponse.result)); | ||
// //@ts-ignore | ||
// expect(txResponse.result).toBeOk(Cl.bool(true)); | ||
}); | ||
|
||
it('should not allow non subject to buy first share', () => { | ||
const buyNonSubjectShareResponse = simnet.callPublicFn( | ||
'keys', | ||
'buy-keys', | ||
[Cl.standardPrincipal(address3), Cl.uint(1)], | ||
address2 | ||
); | ||
//@ts-ignore | ||
expect(buyNonSubjectShareResponse.result).toBeErr(Cl.uint(500)); | ||
}); | ||
|
||
it('should allow subject to buy first share', () => { | ||
const buySubjectShareResponse = simnet.callPublicFn( | ||
'keys', | ||
'buy-keys', | ||
[Cl.standardPrincipal(address2), Cl.uint(1)], | ||
address2 | ||
); | ||
console.log(Cl.prettyPrint(getPriceResponse.result)); // u10010 | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
console.log(Cl.prettyPrint(buySubjectShareResponse.result)); | ||
//@ts-ignore | ||
expect(getPriceResponse.result).toBeUint(10010); | ||
expect(buySubjectShareResponse.result).toBeOk(Cl.bool(true)); | ||
}); | ||
}); |