GithubHelp home page GithubHelp logo

ohager / game-contracts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from evolverde/game-contracts

0.0 0.0 0.0 29 KB

just a collection of SmartC-Contracts wich used inGame

License: Apache License 2.0

C 89.03% TypeScript 10.97%

game-contracts's Introduction

Game-Contracts

just a collection of SmartC-Contracts wich used inGame

Development

A secure and fast way to develop Smart Contracts in Signum is using the TDD approach, i.e. Test-Driven Development. This allows to programmatically verify the Smart Contracts functionality, while also speed up development and foremost confidence and security.

Each contract "lives" in its own folder aside its test cases, as proposed here.

Installation

  1. Install NodeJS 18+
  2. In this projects root folder simply run npm install
  3. Run npm test to run the tests

Implementing Tests

It's recommended to create a folder for each "method" of the contract you want to test. A test needs always

  1. A collection of (simulated) Transactions, called Scenarios
  2. A collection of Test cases (see (how to write test with Vitest))

It turned out that it's also good to keep contract specific constants, i.e. map keys, method ids, accounts, etc in a separate file, which you call globals.ts, constants.ts, or context.ts

In your test you have to instantiate the testbed, like this

const testbed = new SimulatorTestbed(Scenario) // instantiate with a Scenario
    .loadContract(Context.ContractPath)
    .runScenario();

Once executed, the testbed object maintains a completely emulated blockchain environment for the given scenario, with access to

  • transactions
  • contracts (and their inner state and maps)
  • accounts
  • etc.

When debugging while testing one can inspect all these objects.

For complete methods and object of the testbed look here

Running Code in Web Simulator

Sometimes it's necessary for in-situ debugging to run the contract in the Web Simulator.

  1. Copy the contract code into the simulator
  2. use toSimulatorTransactions to convert your scenario into copy&pastable JSON for the Simulator.

Now, you can debug the contract interactively (which is not supported by the testbed)

game-contracts's People

Contributors

ohager avatar evolverde avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.