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

feat: fee in assets #134

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 11 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ serde = { version = "1", features = ["derive", "rc"] }
tracing = "0.1"
scale-info = "2"
axum-macros = "0.4"
primitive-types = { version = "0.12", features = ["codec"] }
primitive-types = { version = "0.13", features = ["codec"] }
jsonrpsee = { version = "0.24", features = ["ws-client"] }
thiserror = "1"
frame-metadata = "16"
frame-metadata = "17"
const-hex = "1"
codec = { package = "parity-scale-codec", version = "3", features = [
"chain-error",
Expand Down
1 change: 1 addition & 0 deletions src/chain/payout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub async fn payout(
block,
block_number,
0,
currency.asset_id,
)?;

let sign_this = batch_transaction
Expand Down
4 changes: 4 additions & 0 deletions src/chain/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ pub fn construct_batch_transaction(
block: BlockHash,
block_number: u32,
nonce: u32,
asset: Option<u32>,
) -> Result<TransactionToFill, ChainError> {
let mut transaction_to_fill = TransactionToFill::init(&mut (), metadata, genesis_hash.0)?;

Expand Down Expand Up @@ -296,6 +297,9 @@ pub fn construct_batch_transaction(

transaction_to_fill.populate_block_info(Some(block.0), Some(block_number.into()));
transaction_to_fill.populate_nonce(nonce);
if let Some(asset) = asset {
transaction_to_fill.try_default_tip_assets_in_given_asset(&mut (), metadata, asset);
}

for ext in transaction_to_fill.extensions.iter_mut() {
if ext.finalize().is_none() {
Expand Down
53 changes: 46 additions & 7 deletions tests/kalatori-api-test-suite/tests/order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ describe('Order Endpoint Blackbox Tests', () => {
throw new Error('check all environment variables are defined');
}
const dotOrderData = {
amount: 4, // Crucial to test with more than existential amount which is 1 DOT
amount: 40, // Crucial to test with more than existential amount which is 1 DOT
currency: 'DOT',
callback: 'https://example.com/callback'
};

const usdcOrderData = {
amount: 1,
amount: 100,
currency: 'USDC',
callback: 'https://example.com/callback'
};
Expand Down Expand Up @@ -233,7 +233,7 @@ describe('Order Endpoint Blackbox Tests', () => {
expect(repaidOrderDetails.withdrawal_status).toBe('completed');
}, 100000);

it.skip('should create, repay, and automatically withdraw an order in USDC', async () => {
it('should create, repay, and automatically withdraw an order in USDC', async () => {
const orderId = generateRandomOrderId();
await createOrder(orderId, usdcOrderData);
const orderDetails = await getOrderDetails(orderId);
Expand All @@ -255,9 +255,9 @@ describe('Order Endpoint Blackbox Tests', () => {
expect(repaidOrderDetails.withdrawal_status).toBe('completed');
}, 50000);

it.skip('should not automatically withdraw an order until fully repaid', async () => {
it('should not automatically withdraw DOT order until fully repaid', async () => {
const orderId = generateRandomOrderId();
await createOrder(orderId, usdcOrderData);
await createOrder(orderId, dotOrderData);
const orderDetails = await getOrderDetails(orderId);
const paymentAccount = orderDetails.payment_account;
expect(paymentAccount).toBeDefined();
Expand Down Expand Up @@ -286,15 +286,54 @@ describe('Order Endpoint Blackbox Tests', () => {
orderDetails.currency.asset_id
);

// lets wait for the changes to get propagated on chain and app to catch them
await new Promise(resolve => setTimeout(resolve, 20000));

repaidOrderDetails = await getOrderDetails(orderId);
expect(repaidOrderDetails.payment_status).toBe('paid');
expect(repaidOrderDetails.withdrawal_status).toBe('completed');
}, 100000);

it('should not automatically withdraw USDC order until fully repaid', async () => {
const orderId = generateRandomOrderId();
await createOrder(orderId, usdcOrderData);
const orderDetails = await getOrderDetails(orderId);
const paymentAccount = orderDetails.payment_account;
expect(paymentAccount).toBeDefined();

const halfAmount = orderDetails.amount/2;

// Partial repayment
await transferFunds(
orderDetails.currency.rpc_url,
paymentAccount,
halfAmount,
orderDetails.currency.asset_id
);
// lets wait for the changes to get propagated on chain and app to catch them
await new Promise(resolve => setTimeout(resolve, 15000));

let repaidOrderDetails = await getOrderDetails(orderId);
expect(repaidOrderDetails.payment_status).toBe('pending');
expect(repaidOrderDetails.withdrawal_status).toBe('waiting');

// Full repayment
await transferFunds(
orderDetails.currency.rpc_url,
paymentAccount,
halfAmount+1,
orderDetails.currency.asset_id
);

// lets wait for the changes to get propagated on chain and app to catch them
await new Promise(resolve => setTimeout(resolve, 20000));

repaidOrderDetails = await getOrderDetails(orderId);
expect(repaidOrderDetails.payment_status).toBe('paid');
expect(repaidOrderDetails.withdrawal_status).toBe('completed');
}, 50000);
}, 100000);

it.skip('should not update order if received payment in wrong currency', async () => {
it('should not update order if received payment in wrong currency', async () => {
const orderId = generateRandomOrderId();
await createOrder(orderId, usdcOrderData);
const orderDetails = await getOrderDetails(orderId);
Expand Down
Loading