Skip to content

Commit

Permalink
Merge branch 'main' into forceIpv4
Browse files Browse the repository at this point in the history
  • Loading branch information
frol authored Sep 3, 2024
2 parents fd3a371 + b90f4f6 commit 190ab64
Show file tree
Hide file tree
Showing 85 changed files with 8,747 additions and 6,970 deletions.
131 changes: 131 additions & 0 deletions .github/ISSUE_TEMPLATE/BOUNTY.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: "Simple Bounty"
description: "Use this template to create a HEROES Simple Bounty via Github bot"
title: "Bounty: "
labels: ["bounty"]
assignees: heroes-bot-test
body:
- type: markdown
attributes:
value: |
Hi! Let's set up your bounty! Please don't change the template - @heroes-bot-test won't be able to help you.
- type: dropdown
id: type
attributes:
label: What talent are you looking for?
options:
- Marketing
- Development
- Design
- Other
- Content
- Research
- Audit

- type: textarea
id: description
attributes:
label: What you need to be done?

- type: dropdown
id: tags
attributes:
label: Tags
description: Add tags that match the topic of the work
multiple: true
options:
- API
- Blockchain
- Community
- CSS
- DAO
- dApp
- DeFi
- Design
- Documentation
- HTML
- Javascript
- NFT
- React
- Rust
- Smart contract
- Typescript
- UI/UX
- web3
- Translation
- Illustration
- Branding
- Copywriting
- Blogging
- Editing
- Video Creation
- Social Media
- Graphic Design
- Transcription
- Product Design
- Artificial Intelligence
- Quality Assurance
- Risk Assessment
- Security Audit
- Bug Bounty
- Code Review
- Blockchain Security
- Smart Contract Testing
- Penetration Testing
- Vulnerability Assessment
- BOS
- News
- Hackathon
- NEARCON2023
- NEARWEEK

- type: input
id: deadline
attributes:
label: Deadline
description: "Set a deadline for your bounty. Please enter the date in format: DD.MM.YYYY"
placeholder: "19.05.2027"

- type: dropdown
id: currencyType
attributes:
label: Currency
description: What is the currency you want to pay?
options:
- USDC.e
- USDT.e
- DAI
- wNEAR
- USDt
- XP
- marmaj
- NEKO
- JUMP
- USDC
- NEARVIDIA
default: 0
validations:
required: true

- type: input
id: currencyAmount
attributes:
label: Amount
description: How much it will be cost?

- type: markdown
attributes:
value: "## Advanced settings"

- type: checkboxes
id: kyc
attributes:
label: KYC
description: "Use HEROES' KYC Verification, only applicants who passed HEROES' KYC can apply and work on this bounty!"
options:
- label: Use KYC Verification

- type: markdown
attributes:
value: |
### This cannot be changed once the bounty is live!
4 changes: 2 additions & 2 deletions .github/workflows/tests-sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest]
node-version: [14, 16, 18, 20]
node-version: [16]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
Expand All @@ -19,4 +19,4 @@ jobs:
- name: Install dependencies
run: yarn
- name: Run tests
run: yarn test:sandbox:ci --fail-fast
run: yarn test:sandbox:ci-with-ignore --fail-fast
45 changes: 45 additions & 0 deletions .github/workflows/typedoc-generator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy TypeDoc on GitHub pages

on:
push:
branches:
main

env:
NODE_VERSION: 18.x.x
ENTRY_FILE: 'packages'
CONFIG_PATH: 'tsconfig.base.json'
USES_PNPM: 'true'

jobs:
deploy:
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn install

- name: Build project
run: yarn build

- name: Build documentation
run: yarn docs:generate

- name: Deploy to GitHub pages
uses: JamesIves/github-pages-deploy-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
folder: docs
clean: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ coverage
**/dist/tsconfig.tsbuildinfo
lerna-debug.log
yarn-error.log
.idea
package-lock.json
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,18 @@ It is true that you can alter contract code, accounts, and access keys using nor

To see an example of how to do this, see the [patch-state test](https://github.com/near/workspaces-js/blob/main/__tests__/02.patch-state.ava.ts).

Time Traveling
===============

In Sandbox-mode, you can forward time-related state (the block height, timestamp and epoch height) with `fastForward`.

This means contracts which require time sensitive data do not need to sit and wait the same amount of time for blocks on the sandbox to be produced.
We can simply just call the api to get us further in time.

For an example, see the [fast-forward test](./__tests__/08.fast-forward.ava.ts)

Note: `fastForward` does not speed up an in-flight transactions.

Pro Tips
========

Expand All @@ -292,3 +304,18 @@ Pro Tips
* specify which port to run on

* and more!

Env variables
========
```text
NEAR_CLI_MAINNET_RPC_SERVER_URL
NEAR_CLI_TESTNET_RPC_SERVER_URL
```
Clear them in case you want to get back to the default RPC server.

Example:

```shell
export NEAR_CLI_MAINNET_RPC_SERVER_URL=<put_your_rpc_server_url_here>
```
here is a testcase: [jsonrpc.ava.js](./packages/js/__tests__/jsonrpc.ava.js)
18 changes: 9 additions & 9 deletions __tests__/05.spoon-contract-to-sandbox.ava.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ test.afterEach.always(async t => {
test('using `withData` for contracts > 50kB fails', async t => {
const root = t.context.worker.rootAccount;

t.regex(
await captureError(async () => {
await root.importContract({
mainnetContract: REF_FINANCE_ACCOUNT,
withData: true,
blockId: 50_000_000,
});
}),
new RegExp(`State of contract ${REF_FINANCE_ACCOUNT} is too large to be viewed`),
const error_response = await captureError(async () => {
await root.importContract({
mainnetContract: REF_FINANCE_ACCOUNT,
withData: true,
blockId: 50_000_000,
});
});
t.assert(
error_response.includes('is larger than allowed') || error_response.includes('is too large to be viewed'),
);
});

Expand Down
40 changes: 40 additions & 0 deletions __tests__/08.custom-network.ava.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import process from 'process';
import {Worker, getNetworkFromEnv} from 'near-workspaces';
import anyTest, {TestFn} from 'ava';

// To run this test, you need to set the NEAR_RPC_API_KEY environment variable tied the Pagoda testnet network.
// And the NEAR_WORKSPACES_NETWORK environment variable to 'custom'.
//
// Sample: NEAR_WORKSPACES_NETWORK=custom NEAR_RPC_API_KEY="xxx" yarn test...
if (getNetworkFromEnv() === 'custom' && process.env.NEAR_RPC_API_KEY !== '') {
const test = anyTest as TestFn<{
worker: Worker;
}>;

test.before(async t => {
const worker = await Worker.init({
network: 'custom',
rpcAddr: 'https://near-testnet.api.pagoda.co/rpc/v1/',
apiKey: process.env.NEAR_RPC_API_KEY!,
});
t.context.worker = worker;
});

test.after.always(async t => {
await t.context.worker.tearDown().catch(error => {
console.log('Failed to tear down the worker:', error);
});
});

test('Ping network', async t => {
try {
await t.context.worker.provider.block({finality: 'final'});
} catch (error: unknown) {
t.fail(`Failed to ping the network: ${error as string}`);
return;
}

t.pass('Network pinged successfully!');
});
}

54 changes: 54 additions & 0 deletions __tests__/08.fast-forward.ava.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {NearAccount, getNetworkFromEnv} from 'near-workspaces';
import anyTest, {TestFn} from 'ava';
import {Worker} from 'near-workspaces/dist/worker';

// The contract provided contains only one view call, returning the
// block_timestamp and epoch_height of the current block as a tuple.
// Source is here <https://github.com/near/near-workspaces-rs/blob/main/examples/simple-contract/src/lib.rs>
const contract_wasm = '__tests__/build/debug/simple_contract.wasm';

// Represents the timestamp and epoch_height result from the view call.
type EnvData = [number, number];

if (getNetworkFromEnv() === 'sandbox') {
const test = anyTest as TestFn<{
worker: Worker;
contract: NearAccount;
}>;

test.beforeEach(async t => {
const worker = await Worker.init();
const root = worker.rootAccount;
const contract = await root.devDeploy(contract_wasm);

t.context.worker = worker;
t.context.contract = contract;
});

test.afterEach.always(async t => {
await t.context.worker.tearDown().catch(error => {
console.log('Failed to tear down the worker:', error);
});
});

test('Fast Forward', async t => {
const before = await t.context.contract.view('current_env_data');
const env_before = before as EnvData;
console.log(`Before: timestamp = ${env_before[0]}, epoch_height = ${env_before[1]}`);

const forward_height = 10_000;

// Call into fastForward. This will take a bit of time to invoke, but is
// faster than manually waiting for the same amounts of blocks to be produced
await t.context.worker.provider.fastForward(forward_height);

const after = await t.context.contract.view('current_env_data');
const env_after = after as EnvData;
console.log(`After: timestamp = ${env_after[0]}, epoch_height = ${env_after[1]}`);

const block = await t.context.worker.provider.block({finality: 'final'});

// Rounding off to nearest hundred, providing wiggle room incase not perfectly `forward_height`
t.true(Math.ceil(block.header.height / 100) * 100 === forward_height);
});
}
Binary file added __tests__/build/debug/simple_contract.wasm
Binary file not shown.
File renamed without changes.
Loading

0 comments on commit 190ab64

Please sign in to comment.