Skip to content

Commit

Permalink
feat: mint_rate_limit added to state with an added check and view func (
Browse files Browse the repository at this point in the history
#48)

* feat: mint_rate_limit added to state with an added check and view func

* fix: make total_cost == price * num of tokens

* fix: test now price is flat and not extra for storage

* fix: pass tests and update types

* fix(CI): only test node 16

* fix(CI): switch back to normal workspaces-js

* fix(CI): break up testnet into two runners

* fix: ensure that linkdrop cost incorporates storage cost
  • Loading branch information
willemneal authored Mar 15, 2022
1 parent e07a2e9 commit 89b473e
Show file tree
Hide file tree
Showing 24 changed files with 2,323 additions and 324 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ jobs:
tests:
strategy:
matrix:
platform: [ubuntu-latest]
node-version: ['14']
toolchain: [stable]
runs-on: ${{ matrix.platform }}
set: ['"*/linkdrop/succ*"', "*/link*/fail*"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "${{ matrix.toolchain }} with rustfmt, and wasm32"
- name: "stable with rustfmt, and wasm32"
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
toolchain: stable
target: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v1
- name: Add wasm32 target
run: rustup target add wasm32-unknown-unknown
- name: install node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
node-version: '16'
- name: Run tests
run: npm i && npm run test:linkdrop
run: npm i && npm run test:testnet ${{ matrix.set }}
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest]
node-version: ['14', '16']
node-version: ['16']
toolchain: [stable]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion __test__/allowance.ava.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Workspace } from "near-willem-workspaces-ava";
import { Workspace } from "near-workspaces-ava";
import { NEAR } from "near-units";
import {
DEFAULT_SALE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {
Workspace,
NearAccount,
randomAccountId,
} from "near-willem-workspaces-ava";
} from "near-workspaces-ava";
import {
ava
} from "near-willem-workspaces-ava";
} from "near-workspaces-ava";
import { NEAR, Gas } from "near-units";
import { readFile } from "fs/promises";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import {
Workspace,
NearAccount,
randomAccountId,
} from "near-willem-workspaces-ava";
import {
ava
} from "near-willem-workspaces-ava";
import { NEAR, Gas } from "near-units";
import { Workspace, randomAccountId } from "near-workspaces-ava";
import { ava } from "near-workspaces-ava";
import { NEAR } from "near-units";
import { readFile } from "fs/promises";
import {
ActualTestnet,
createLinkdrop,
getTokens,
checkKey,
BalanceDelta,
claim,
claim_raw,
// repeat,
// zeroDelta,
hasDelta,
getDelta,
create_account_and_claim,
Expand All @@ -29,8 +18,6 @@ import {
const base_cost = NEAR.parse("1 N");
const min_cost = NEAR.parse("0.01 N");



if (Workspace.networkIsTestnet()) {
const runner = Workspace.init(
{ initialBalance: NEAR.parse("15 N").toString() },
Expand Down Expand Up @@ -69,7 +56,6 @@ if (Workspace.networkIsTestnet()) {
);
});
await delta.isGreaterOrEqual(NEAR.from(0));
t.log(await delta.toHuman());
const tokens = await getTokens(tenk, alice);
t.assert(tokens.length == 1, "should contain only one token");
t.log(
Expand Down Expand Up @@ -114,8 +100,6 @@ if (Workspace.networkIsTestnet()) {
}
);



// runner.test(
// "Spam `claim` to send to non-existent account",
// async (t, { root, tenk }) => {
Expand Down Expand Up @@ -185,7 +169,6 @@ if (Workspace.networkIsTestnet()) {
// await new_account.delete(root.accountId);
}
);

} else {
ava("skipped on sandbox", (t) => t.assert(true));
}
Expand Down
2 changes: 1 addition & 1 deletion __test__/mintbase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Workspace, NearAccount, ONE_NEAR } from "near-willem-workspaces-ava";
import { Workspace, NearAccount, ONE_NEAR } from "near-workspaces-ava";
import { NEAR, Gas } from "near-units";
import { nftTokensForOwner } from "./util";

Expand Down
17 changes: 3 additions & 14 deletions __test__/nft.ava.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Workspace, NearAccount } from "near-willem-workspaces-ava";
import { Workspace, NearAccount } from "near-workspaces-ava";
import { NEAR } from "near-units";
import {
costPerToken,
Expand Down Expand Up @@ -34,20 +34,9 @@ const runner = Workspace.init(
}
);

runner.test("can get cost per token", async (t, { root, tenk }) => {
runner.test("can get cost per token", async (t, { tenk }) => {
const cost = await costPerToken(tenk, 1);
const storageCost = await tokenStorageCost(tenk);
t.log(
"One token costs " +
cost.toHuman() +
"to buy and " +
storageCost.toHuman() +
" to store"
);
t.deepEqual(cost.toBigInt(), price.add(storageCost).toBigInt());
// if (cost.toBigInt() > 0) {
// t.assert(cost.gt(await costPerToken(tenk, 24)));
// }
t.deepEqual(cost.toBigInt(), price.toBigInt());
});

async function assertXTokens(t, root: NearAccount, tenk, num) {
Expand Down
2 changes: 1 addition & 1 deletion __test__/paras.ava.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Workspace, NearAccount, ONE_NEAR } from "near-willem-workspaces-ava";
import { Workspace, NearAccount, ONE_NEAR } from "near-workspaces-ava";
import { NEAR, Gas } from "near-units";
import {
nftTokensForOwner,
Expand Down
2 changes: 1 addition & 1 deletion __test__/premint.ava.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ONE_NEAR, Workspace } from "near-willem-workspaces-ava";
import { ONE_NEAR, Workspace } from "near-workspaces-ava";
import { NEAR } from "near-units";
import {
claim,
Expand Down
2 changes: 1 addition & 1 deletion __test__/royalties.ava.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Workspace, NearAccount } from "near-willem-workspaces-ava";
import { Workspace, NearAccount } from "near-workspaces-ava";
import { NEAR } from "near-units";
import { DEFAULT_SALE, deploy, getDelta, mint, now, totalCost } from "./util";
import { Royalties, Sale } from "..";
Expand Down
2 changes: 1 addition & 1 deletion __test__/start_at_one.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import { Workspace, NearAccount } from "near-willem-workspaces-ava";
// import { Workspace, NearAccount } from "near-workspaces-ava";
// import { NEAR } from "near-units";
// import {
// costPerToken,
Expand Down
2 changes: 1 addition & 1 deletion __test__/util/delta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NEAR, NearAccount } from "near-willem-workspaces-ava";
import { NEAR, NearAccount } from "near-workspaces-ava";

export class NEARDelta {
static readonly ZERO_NEAR = NEAR.from(0);
Expand Down
4 changes: 2 additions & 2 deletions __test__/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
KeyPair,
PublicKey,
AccountManager,
} from "near-willem-workspaces";
import { ONE_NEAR, TransactionResult } from "near-willem-workspaces-ava";
} from "near-workspaces";
import { ONE_NEAR, TransactionResult } from "near-workspaces-ava";
import { binPath } from "./bin";
import { BalanceDelta, getDelta } from "./delta";
import {Contract} from "../..";
Expand Down
2 changes: 1 addition & 1 deletion ava.config.cjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("near-willem-workspaces-ava/ava.config.cjs")
module.exports = require("near-workspaces-ava/ava.config.cjs")
Loading

0 comments on commit 89b473e

Please sign in to comment.