Skip to content

Commit

Permalink
counter, status message, and cross-contract examples refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
volovyks committed Aug 30, 2022
1 parent 49b2a46 commit cc96720
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 26 deletions.
3 changes: 0 additions & 3 deletions examples/__tests__/test-cross-contract-call.ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ test.beforeEach(async t => {
'./build/status-message.wasm',
);

// Init the contract
await statusMessage.call(statusMessage, 'init', {});

// Deploy the onCall contract.
const onCall = await root.devDeploy(
'./build/cross-contract-call.wasm',
Expand Down
3 changes: 0 additions & 3 deletions examples/__tests__/test-status-message.ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ test.before(async t => {
'./build/status-message.wasm',
);

// Init the contract
await statusMessage.call(statusMessage, 'init', {});

// Create test users
const ali = await root.createSubAccount('ali');
const bob = await root.createSubAccount('bob');
Expand Down
2 changes: 1 addition & 1 deletion examples/src/clean-state.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NearBindgen, call, view, near } from 'near-sdk-js'

@NearBindgen({ requireInit: false })
@NearBindgen({})
class CleanState {
@call
clean({ keys }) {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/counter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NearBindgen, near, call, view, initialize } from 'near-sdk-js'
import { isUndefined } from 'lodash-es'

@NearBindgen
@NearBindgen({})
class Counter {
@initialize
init({ initial = 0 }) {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NearBindgen, near, call, view, initialize } from 'near-sdk-js'
import { isUndefined } from 'lodash-es'
import { log } from './log'

@NearBindgen
@NearBindgen({})
class Counter {
count: number;

Expand Down
14 changes: 5 additions & 9 deletions examples/src/cross-contract-call.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NearContract, NearBindgen, call, view, near, bytes } from 'near-sdk-js'
import { NearBindgen, call, view, initialize, near, bytes } from 'near-sdk-js'

@NearBindgen
class OnCall extends NearContract {
constructor({ statusMessageContract }) {
super()
@NearBindgen({ requireInit: true })
class OnCall {
@initialize
init({ statusMessageContract }) {
this.personOnCall = "undefined"
this.statusMessageContract = statusMessageContract
}
Expand Down Expand Up @@ -37,8 +37,4 @@ class OnCall extends NearContract {
near.log(`Returning person on-call: ${this.personOnCall}`)
return this.personOnCall
}

default() {
return new OnCall({ statusMessageContract: '' })
}
}
11 changes: 3 additions & 8 deletions examples/src/status-message.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NearContract, NearBindgen, call, view, near } from 'near-sdk-js'
import { NearBindgen, call, view, near } from 'near-sdk-js'

@NearBindgen
class StatusMessage extends NearContract {
@NearBindgen({})
class StatusMessage {
constructor() {
super()
this.records = {}
}

Expand All @@ -19,9 +18,5 @@ class StatusMessage extends NearContract {
near.log(`get_status for account_id ${account_id}`)
return this.records[account_id] || null
}

default() {
return new StatusMessage()
}
}

0 comments on commit cc96720

Please sign in to comment.