Skip to content

Commit

Permalink
Merge pull request #11 from nearprotocol/j-jest
Browse files Browse the repository at this point in the history
Put new project on ci (in nearcore) + fixes
  • Loading branch information
janedegtiareva committed Mar 23, 2019
2 parents 02bc82c + e160c23 commit c5a2be8
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 22 deletions.
20 changes: 17 additions & 3 deletions blank_project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@

The contract implements a single function to return a greeting.

## To Run
## To Run on local node
Step 1: Create account for the contract and deploy the contract.
```
npm install
near create_account --account_id id
near deploy --account_id id
```

Step 2:
modify src/settings.js line that sets the contractName. Set it to id from step 1.
```
const contractName = "contractId"; /* TODO: fill this in! */
```

Step 3:
Open src/main.html in your browser.
That's it!

## To Test

*In NEAR Studio (https://studio.nearprotocol.com)*
## To Test

```
npm install
Expand Down
1 change: 1 addition & 0 deletions blank_project/neardev/devkey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"public_key":"HQT9s2XAuRNkCMyykWudxAnbS6UMYhYHZ9o5RQb513xC","secret_key":"ds1tUZviLRhaaEuiqhRNFFapSRHg8S98nphxNKAgVhUepqH4v9mjHvpNnpQ4GNhi29k5fpwDbyjZnJaCSwbEznk","account_id":"contract2"}
1 change: 1 addition & 0 deletions blank_project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"assemblyscript": "github:nearprotocol/assemblyscript.git",
"gulp": "^3",
"assemblyscript-json": "github:nearprotocol/assemblyscript-json",
"jest": "^22.4.4",
"jest-environment-node": "^24.5.0",
"near-runtime-ts": "github:nearprotocol/near-runtime-ts",
"near-shell": "0.0.10"
Expand Down
5 changes: 3 additions & 2 deletions blank_project/src/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
Contract says:
<h1 id="contract-message"></h1>
</div>
<script src="https://cdn.jsdelivr.net/npm/nearlib@0.3.3/dist/nearlib.js"></script>
<script src="https://cdn.jsdelivr.net/npm/nearlib@0.3.5/dist/nearlib.js"></script>
<script src="./settings.js"></script>
<script src="./main.js"></script>
</body>
</html>
<!-- << markup-snippet -->
<!-- << markup-snippet -->
11 changes: 5 additions & 6 deletions blank_project/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
async function doInitContract() {
// Getting config from cookies that are provided by the NEAR Studio.
const config = await nearlib.dev.getConfig();
console.log("nearConfig", config);


// Initializing connection to the NEAR DevNet.
window.near = await nearlib.dev.connect();
window.near = await nearlib.dev.connect(settings);

// Initializing our contract APIs by contract name and configuration.
window.contract = await near.loadContract(config.contractName, {
window.contract = await near.loadContract(contractName, {
// NOTE: This configuration only needed while NEAR is still in development
// View methods are read only. They don't modify the state, but usually return some value.
// View methods are read only. They don't modify the state, but usually return some value.
viewMethods: ["hello"],
// Change methods can modify the state. But you don't receive the returned value when called.
changeMethods: [],
Expand Down
6 changes: 6 additions & 0 deletions blank_project/src/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const settings = {
deps: {
createAccount: nearlib.dev.createAccountWithLocalNodeConnection
},
};
const contractName = "contract2"; /* TODO: fill this in! */
10 changes: 5 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ gulp.task('createDevAccount', async function(argv) {
keyStore.setKey(accountId, keyPair);
});

async function deployContractAndWaitForTransaction(accountId, contractName, data, near) {
const deployContractResult = await near.deployContract(contractName, data);
async function deployContractAndWaitForTransaction(accountId, data, near) {
const deployContractResult = await near.deployContract(accountId, data);
const waitResult = await near.waitForTransactionResult(deployContractResult);
return waitResult;
}
Expand Down Expand Up @@ -165,11 +165,11 @@ gulp.task('deploy', async function(argv) {
const contractData = [...fs.readFileSync(argv.wasm_file)];

// Contract name
const contractName = argv.contract_name;
const contractName = accountId;
console.log(
"Starting deployment. Account id " + accountId + ", contract " + contractName + ", url " + nodeUrl, ", file " + argv.wasm_file);
"Starting deployment. Account id " + accountId + ", contract " + accountId + ", url " + nodeUrl, ", file " + argv.wasm_file);
const res = await deployContractAndWaitForTransaction(
accountId, contractName, contractData, near);
accountId, contractData, near);
if (res.status == "Completed") {
console.log("Deployment succeeded.");
} else {
Expand Down
5 changes: 0 additions & 5 deletions near
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ const deploy = {
command: 'deploy',
desc: 'deploy your smart contract',
builder: (yargs) => yargs
.option('contract_name', {
desc: 'Contract name',
type: 'string',
required: true
})
.option('node_url', {
desc: 'Near node url',
type: 'string',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "near-shell",
"version": "0.0.11",
"version": "0.0.13",
"description": "Command line utilities to interact with near blockchain",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit c5a2be8

Please sign in to comment.