Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cryshado committed Jun 5, 2022
1 parent d4d8aa1 commit 1c2aeaf
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 29 deletions.
6 changes: 6 additions & 0 deletions func/struct/get-met.func
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@

(int wc, int addr) = parse_std_addr(nft_owner);
return (wc, addr);
}

(int) bid_info() method_id {
init_data();

return (last_bid);
}
18 changes: 11 additions & 7 deletions func/struct/handles.func
Original file line number Diff line number Diff line change
Expand Up @@ -179,28 +179,32 @@
last_member = sender_addr;
last_bid = msg_value;
pack_data();
return ();
}
else {
handle::return_transaction(sender_addr);
return ();
}
return ();
}

if (msg_value < (last_bid + min_step)) {
handle::return_transaction(sender_addr);
return ();
}

builder return_prev_bid = begin_cell()
.store_uint(0x18, 6)
.store_slice(last_member)
.store_coins(last_bid)
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
.store_uint(0, 32)
.store_slice(msg::bid_return());
.store_uint(0x18, 6)
.store_slice(last_member)
.store_coins(last_bid)
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
.store_uint(0, 32)
.store_slice(msg::bid_return());

send_raw_message(return_prev_bid.end_cell(), 2);

last_member = sender_addr;
last_bid = msg_value;

pack_data();
}
71 changes: 49 additions & 22 deletions test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
toNano,
Address
} from 'ton'
import { SmartContract } from 'ton-contract-executor'
import { OutAction, SmartContract } from 'ton-contract-executor'
import { encodeAucStorage, MSG } from '../src/encoder'
import { getRandSigner } from '../src/utils'

Expand Down Expand Up @@ -59,7 +59,7 @@ describe('SmartContract main tests', () => {
royaltyFeePercent: 5
},
{
mminBid: toNano(0.1),
mminBid: toNano(1),
mmaxBid: toNano(100),
minStep: toNano(0.1),
endTime: ~~(Date.now() / 1000) + (60 * 60 * 24) // 24h
Expand All @@ -81,6 +81,40 @@ describe('SmartContract main tests', () => {
})

describe('contract', () => {
interface ISimpleResult {
exit_code: number
out: OutAction[]
}

async function placeBidsOrder (values: number[]): Promise<ISimpleResult[]> {
const resultArr: ISimpleResult[] = []
await Promise.all(values.map(async (value) => {
const result = await smc.sendInternalMessage(new InternalMessage({
to: SELF_ADDR,
from: getRandSigner(),
value: toNano(value),
bounce: true,
body: EMPTY_BODY
}))
resultArr.push({ exit_code: result.exit_code, out: result.actionList })
const get = await smc.invokeGetMethod('bid_info', [])
console.log('last_bid:', Number(get.result.toString()) / 1e9)
}))

return resultArr
}

async function simpleTransferNFT (): Promise<void> {
const msg = MSG.nftOwnerAssigned(queryId(), NFT_OWNER)
await smc.sendInternalMessage(new InternalMessage({
to: SELF_ADDR,
from: NFT_ADDR,
value: toNano(0.1),
bounce: true,
body: new CommonMessageInfo({ body: new CellMessage(msg) })
}))
}

it('1) simple transfer nft', async () => {
const msg = MSG.nftOwnerAssigned(queryId(), NFT_OWNER)

Expand Down Expand Up @@ -175,28 +209,21 @@ describe('SmartContract main tests', () => {
})

it('6) place bids in order', async () => {
// for first transfer nft
const msg = MSG.nftOwnerAssigned(queryId(), NFT_OWNER)
await smc.sendInternalMessage(new InternalMessage({
to: SELF_ADDR,
from: NFT_ADDR,
value: toNano(0.1),
bounce: true,
body: new CommonMessageInfo({ body: new CellMessage(msg) })
}))
await simpleTransferNFT()

await Promise.all([ 10, 5, 30 ].map(async (value) => {
const result = await smc.sendInternalMessage(new InternalMessage({
to: SELF_ADDR,
from: getRandSigner(),
value: toNano(value),
bounce: true,
body: EMPTY_BODY
}))
const results = await placeBidsOrder([ 10, 15, 30 ])
results.forEach((res) => {
expect(res.exit_code).to.equal(TVM_EXIT_CODES.OK)
})
})

console.log(result)
expect(result.exit_code).to.equal(TVM_EXIT_CODES.OK)
}))
it('6.1) place bids in incorrect order', async () => {
await simpleTransferNFT()

const results = await placeBidsOrder([ 10, 5 ])
results.forEach((res) => {
console.log(res)
})
})
})

Expand Down

0 comments on commit 1c2aeaf

Please sign in to comment.