Best of Crypto

Best of Crypto

1661014920

The TNT-20 Smart Contract Example with Basic Unit Tests

TNT-20 Smart Contract Example

This repository contains a TNT-20 Smart contract example with basic unit tests

Run test

Setup

cd tests
npm install

Modify the following lines in tests/test/mintable-tnt20.test.js with the wallet addresses and private keys for your test.

const AddressAdmin = "ADMIN_WALLET_ADDRESS";
const AddressUser1 = "USER_1_WALLET_ADDRESS";
const AddressUser2 = "USER_2_WALLET_ADDRESS";
const PrivateKeyAdmin = "ADMIN_WALLET_PRIVATE_KEY";
const PrivateKeyUser1 = "USER_1_WALLET_PRIVATE_KEY";
const PrivateKeyUser2 = "USER_2_WALLET_PRIVATE_KEY";

Then, send a small amount of TFUEL (e.g. 50 TFUEL) to each of the above wallets on the Theta Mainnet.

Run tests

npm run test

Download details:

Author: thetatoken
Source code: https://github.com/thetatoken/tnt-20-token-example

#theta #blockchain #web3 #ethereum #solidity #smartcontract #javascript

What is GEEK

Buddha Community

The TNT-20 Smart Contract Example with Basic Unit Tests
Lawrence  Lesch

Lawrence Lesch

1677668905

TS-mockito: Mocking Library for TypeScript

TS-mockito

Mocking library for TypeScript inspired by http://mockito.org/

1.x to 2.x migration guide

1.x to 2.x migration guide

Main features

  • Strongly typed
  • IDE autocomplete
  • Mock creation (mock) (also abstract classes) #example
  • Spying on real objects (spy) #example
  • Changing mock behavior (when) via:
  • Checking if methods were called with given arguments (verify)
    • anything, notNull, anyString, anyOfClass etc. - for more flexible comparision
    • once, twice, times, atLeast etc. - allows call count verification #example
    • calledBefore, calledAfter - allows call order verification #example
  • Resetting mock (reset, resetCalls) #example, #example
  • Capturing arguments passed to method (capture) #example
  • Recording multiple behaviors #example
  • Readable error messages (ex. 'Expected "convertNumberToString(strictEqual(3))" to be called 2 time(s). But has been called 1 time(s).')

Installation

npm install ts-mockito --save-dev

Usage

Basics

// Creating mock
let mockedFoo:Foo = mock(Foo);

// Getting instance from mock
let foo:Foo = instance(mockedFoo);

// Using instance in source code
foo.getBar(3);
foo.getBar(5);

// Explicit, readable verification
verify(mockedFoo.getBar(3)).called();
verify(mockedFoo.getBar(anything())).called();

Stubbing method calls

// Creating mock
let mockedFoo:Foo = mock(Foo);

// stub method before execution
when(mockedFoo.getBar(3)).thenReturn('three');

// Getting instance
let foo:Foo = instance(mockedFoo);

// prints three
console.log(foo.getBar(3));

// prints null, because "getBar(999)" was not stubbed
console.log(foo.getBar(999));

Stubbing getter value

// Creating mock
let mockedFoo:Foo = mock(Foo);

// stub getter before execution
when(mockedFoo.sampleGetter).thenReturn('three');

// Getting instance
let foo:Foo = instance(mockedFoo);

// prints three
console.log(foo.sampleGetter);

Stubbing property values that have no getters

Syntax is the same as with getter values.

Please note, that stubbing properties that don't have getters only works if Proxy object is available (ES6).

Call count verification

// Creating mock
let mockedFoo:Foo = mock(Foo);

// Getting instance
let foo:Foo = instance(mockedFoo);

// Some calls
foo.getBar(1);
foo.getBar(2);
foo.getBar(2);
foo.getBar(3);

// Call count verification
verify(mockedFoo.getBar(1)).once();               // was called with arg === 1 only once
verify(mockedFoo.getBar(2)).twice();              // was called with arg === 2 exactly two times
verify(mockedFoo.getBar(between(2, 3))).thrice(); // was called with arg between 2-3 exactly three times
verify(mockedFoo.getBar(anyNumber()).times(4);    // was called with any number arg exactly four times
verify(mockedFoo.getBar(2)).atLeast(2);           // was called with arg === 2 min two times
verify(mockedFoo.getBar(anything())).atMost(4);   // was called with any argument max four times
verify(mockedFoo.getBar(4)).never();              // was never called with arg === 4

Call order verification

// Creating mock
let mockedFoo:Foo = mock(Foo);
let mockedBar:Bar = mock(Bar);

// Getting instance
let foo:Foo = instance(mockedFoo);
let bar:Bar = instance(mockedBar);

// Some calls
foo.getBar(1);
bar.getFoo(2);

// Call order verification
verify(mockedFoo.getBar(1)).calledBefore(mockedBar.getFoo(2));    // foo.getBar(1) has been called before bar.getFoo(2)
verify(mockedBar.getFoo(2)).calledAfter(mockedFoo.getBar(1));    // bar.getFoo(2) has been called before foo.getBar(1)
verify(mockedFoo.getBar(1)).calledBefore(mockedBar.getFoo(999999));    // throws error (mockedBar.getFoo(999999) has never been called)

Throwing errors

let mockedFoo:Foo = mock(Foo);

when(mockedFoo.getBar(10)).thenThrow(new Error('fatal error'));

let foo:Foo = instance(mockedFoo);
try {
    foo.getBar(10);
} catch (error:Error) {
    console.log(error.message); // 'fatal error'
}

Custom function

You can also stub method with your own implementation

let mockedFoo:Foo = mock(Foo);
let foo:Foo = instance(mockedFoo);

when(mockedFoo.sumTwoNumbers(anyNumber(), anyNumber())).thenCall((arg1:number, arg2:number) => {
    return arg1 * arg2; 
});

// prints '50' because we've changed sum method implementation to multiply!
console.log(foo.sumTwoNumbers(5, 10));

Resolving / rejecting promises

You can also stub method to resolve / reject promise

let mockedFoo:Foo = mock(Foo);

when(mockedFoo.fetchData("a")).thenResolve({id: "a", value: "Hello world"});
when(mockedFoo.fetchData("b")).thenReject(new Error("b does not exist"));

Resetting mock calls

You can reset just mock call counter

// Creating mock
let mockedFoo:Foo = mock(Foo);

// Getting instance
let foo:Foo = instance(mockedFoo);

// Some calls
foo.getBar(1);
foo.getBar(1);
verify(mockedFoo.getBar(1)).twice();      // getBar with arg "1" has been called twice

// Reset mock
resetCalls(mockedFoo);

// Call count verification
verify(mockedFoo.getBar(1)).never();      // has never been called after reset

You can also reset calls of multiple mocks at once resetCalls(firstMock, secondMock, thirdMock)

Resetting mock

Or reset mock call counter with all stubs

// Creating mock
let mockedFoo:Foo = mock(Foo);
when(mockedFoo.getBar(1)).thenReturn("one").

// Getting instance
let foo:Foo = instance(mockedFoo);

// Some calls
console.log(foo.getBar(1));               // "one" - as defined in stub
console.log(foo.getBar(1));               // "one" - as defined in stub
verify(mockedFoo.getBar(1)).twice();      // getBar with arg "1" has been called twice

// Reset mock
reset(mockedFoo);

// Call count verification
verify(mockedFoo.getBar(1)).never();      // has never been called after reset
console.log(foo.getBar(1));               // null - previously added stub has been removed

You can also reset multiple mocks at once reset(firstMock, secondMock, thirdMock)

Capturing method arguments

let mockedFoo:Foo = mock(Foo);
let foo:Foo = instance(mockedFoo);

// Call method
foo.sumTwoNumbers(1, 2);

// Check first arg captor values
const [firstArg, secondArg] = capture(mockedFoo.sumTwoNumbers).last();
console.log(firstArg);    // prints 1
console.log(secondArg);    // prints 2

You can also get other calls using first(), second(), byCallIndex(3) and more...

Recording multiple behaviors

You can set multiple returning values for same matching values

const mockedFoo:Foo = mock(Foo);

when(mockedFoo.getBar(anyNumber())).thenReturn('one').thenReturn('two').thenReturn('three');

const foo:Foo = instance(mockedFoo);

console.log(foo.getBar(1));    // one
console.log(foo.getBar(1));    // two
console.log(foo.getBar(1));    // three
console.log(foo.getBar(1));    // three - last defined behavior will be repeated infinitely

Another example with specific values

let mockedFoo:Foo = mock(Foo);

when(mockedFoo.getBar(1)).thenReturn('one').thenReturn('another one');
when(mockedFoo.getBar(2)).thenReturn('two');

let foo:Foo = instance(mockedFoo);

console.log(foo.getBar(1));    // one
console.log(foo.getBar(2));    // two
console.log(foo.getBar(1));    // another one
console.log(foo.getBar(1));    // another one - this is last defined behavior for arg '1' so it will be repeated
console.log(foo.getBar(2));    // two
console.log(foo.getBar(2));    // two - this is last defined behavior for arg '2' so it will be repeated

Short notation:

const mockedFoo:Foo = mock(Foo);

// You can specify return values as multiple thenReturn args
when(mockedFoo.getBar(anyNumber())).thenReturn('one', 'two', 'three');

const foo:Foo = instance(mockedFoo);

console.log(foo.getBar(1));    // one
console.log(foo.getBar(1));    // two
console.log(foo.getBar(1));    // three
console.log(foo.getBar(1));    // three - last defined behavior will be repeated infinity

Possible errors:

const mockedFoo:Foo = mock(Foo);

// When multiple matchers, matches same result:
when(mockedFoo.getBar(anyNumber())).thenReturn('one');
when(mockedFoo.getBar(3)).thenReturn('one');

const foo:Foo = instance(mockedFoo);
foo.getBar(3); // MultipleMatchersMatchSameStubError will be thrown, two matchers match same method call

Mocking interfaces

You can mock interfaces too, just instead of passing type to mock function, set mock function generic type Mocking interfaces requires Proxy implementation

let mockedFoo:Foo = mock<FooInterface>(); // instead of mock(FooInterface)
const foo: SampleGeneric<FooInterface> = instance(mockedFoo);

Mocking types

You can mock abstract classes

const mockedFoo: SampleAbstractClass = mock(SampleAbstractClass);
const foo: SampleAbstractClass = instance(mockedFoo);

You can also mock generic classes, but note that generic type is just needed by mock type definition

const mockedFoo: SampleGeneric<SampleInterface> = mock(SampleGeneric);
const foo: SampleGeneric<SampleInterface> = instance(mockedFoo);

Spying on real objects

You can partially mock an existing instance:

const foo: Foo = new Foo();
const spiedFoo = spy(foo);

when(spiedFoo.getBar(3)).thenReturn('one');

console.log(foo.getBar(3)); // 'one'
console.log(foo.getBaz()); // call to a real method

You can spy on plain objects too:

const foo = { bar: () => 42 };
const spiedFoo = spy(foo);

foo.bar();

console.log(capture(spiedFoo.bar).last()); // [42] 

Thanks


Download Details:

Author: NagRock
Source Code: https://github.com/NagRock/ts-mockito 
License: MIT license

#typescript #testing #mock 

david harper

1610429951

Hire Smart Contract Developers | Smart Contract Development Company India

What are smart contracts?

Smart contracts is a digital code stored in a blockchain and automatically executes when predetermined terms and conditions are met. In Simple terms, they are programs that run by the setup of the people who developed them.They are designed to facilitate, verify, and execute a digital contract between two parties without the involvement of third parties.

Benefits of Smart Contracts

Greater efficiency and speed
Accuracy and transparency
Trust
Robust Security
Independent verification
Advanced data safety
Distributed ledger
Ease of use
Open source technology
Better flexibility
Easy integration
Improved tractability

Where could smart contracts be used?

Today Smart contracts are used in various platforms such as supply-chain management,cross-border financial transactions,document management,enforceability and more. Here are the Sectors where smart contracts plays a huge role ,

  • Supply chain management
  • Insurance
  • Mortgage loans
  • Financial industry
  • Trade Finance
  • Government
  • IT Sector
  • Records
  • Property ownership
  • Medical Research
  • Voting
  • Peer-to-Peer transactions
  • Product development
  • Stocktaking

Steps For Successful Smart Contract Development

There are a few Important things that you need to consider before you develop a Smart Contract,

Ask Yourself -

  • Do You Need A Smart Contract In Your Project?
  • How can i Implement Smart Contract in My Business?
  • If yes, Find out Your Business Requirements
  • Plan your Requirements
  • Find a Trustworthy Smart Contract Developer
  • Develop , Test Your Smart Contract

Ready to develop your smart contract?

I hope this blog was helpful. We think this is the right time for companies to invest in building a blockchain powered Smart Contracts as Blockchain technology and the ecosystem around it is changing fast. If you’re thinking about building a Smart Contract but not sure where to start, contact us, we’re happy to provide free suggestions about how blockchain’s Smart Contracts may fit into your business.

We Employcoder Leading IT Outsourcing Company with a team of Smart Contract Experts. Hire Smart Contract Developers from us who can code bug-free, scalable, innovative, fully-functional smart contracts for your business and make your business or enterprise eye-catchy & trutworthy among the people in the digital globe.

#hire smart contract developers #smart contract developer #smart contract development #smart contract development services, #smart contract development company, #smart contract programmers

Smart Contract Development Company in Washington

We (Codezeros) are Smart Contract Development Company in Washington. We provide the complete solution for smart contracts like smart contract architecture, design & development, auditing & optimization. We have experienced developers who are expert in developing smart contracts as well as DApp development, pitch deck development, and many other services related to Blockchain Technology.

#smart contract creation #smart contract company #blockchain smart contract #smart contract development #smart contract service provider #smart contract development company

james right

james right

1606811633

Smart Contract Development Company, Hire Smart Contract Developer

With the advent of smart contracts, it has become possible for every business to secure its data and to determine success. It is a decentralized solution that enables you to do many tasks while executing in the most optimal manner. All the entrepreneurs and business owners who have adopted this mechanism have received great results. In order to access this service for your company, you need to team up with a smart contract development company. By doing this, you enhance the power of your solution and make things very seamless.

Smart Contract Development Company

What makes a smart contract a perfect solution for my business?

A smart contract enables you to achieve various feats that seem unfathomable. Also, you get to protect the information of your enterprise in the best possible manner. When you have the power to expand your operation, you should be wise enough to choose the most appropriate solution. There are times when you have to think of something exemplary, it also gives you more about the perfection of the tools. At such a time, you need to have a proper understanding of the features and get things planned in a permanent fashion.

It does not matter which domain you are related to, you get to think about the possible solutions from every domain. Also, you get to manage various other tasks that seem very difficult otherwise. Before you introduce this ledger-based framework in your firm, you need to ready for the outcomes. Every time you come across a decentralized network, you start to pave way for something more dynamic. This gives you the power to react on time and with more efficacy for the long term. Also, you get to review the overall working with a set of proficient developers.

Whether you directly connect with the blockchain or not, your business draws a large number of benefits from the smart contracts. The very core of this solution enables you to create a fitting structure around every company. Also, you get to come with a prominent fix that empowers the proponents of your project. The vision of your investors gets broadened and you get the insights to envision things properly. Every time you do it, you get things worked up properly, you get to maintain a proper flux of funds. In this way, your business gets whatever you want in a very short duration.

How should I develop and implement smart contracts in my business?

By introducing this solution, you prepare your startup to scale up the steps of success. Also, it helps your business overcome all types of issues whether they are temporary in nature or permanent. You need to understand the predilection of every course of action so there is never any obstacle in the way. Moreover, it becomes very easy for your organization to spread its wings because it has befitting tools to support its working. This may also happen in with support structures that ease the expansion of business in a very lesser time.

In every industry, there is a scope of decentralization and you can make it even easier through a string of services. All the crypto-based programs help you get closer to the customers with a reliable method of payment. With this structure, it is possible for every business to do something exceptional. Whether you want it or not, you get to work on many expeditionary campaigns. Also, you help others expand the work and things can get more explicable flawlessly. The working of this solution gives you a high quantum of accuracy in every possible manner.

The prospects of your company can get much better and promising because you have a lesser number of agents deployed. You might find these differences odd, but they can highly impact the development as well as transactions. When you want to touch base with your team or some consultants, you get a better idea about the entire thing. Also, that happens without having you wasting your time. There could be subtle errors in the initial phases of the development of tokens or any other distributed ledger. If decentralization is at the core, you need to have more potential to conceptualize new methods.

How should I find professionals who could develop custom-built smart contracts?

You can certainly get such experts but the search has to be very thorough in nature. Also, the whole thing has to be planned to the hilt and things could be working seamlessly. When you get things working at an impressive pace, you might lack clear objects. Even if there is a projected solution for some problems, you must not employ them before proper rounds of review. This approach gives you satisfactory results in every domain and keeps you one step ahead when it comes to getting what you precisely need.

It is vital that you work with people who have an idea about what’s happening in your firm. By working with such people, you get more certainty in every step sans wasting a large quantum of resources or time. You might be able to find some other options but they all resort to decentralization in the end. The best way to implement this solution is to give more time to every single process through many methods. Also, you need to get things aligned with a proper solution and help the developers give shape to their visions.

Upshot

With the experts of Coin Developer India, it is possible for every startup to get a bespoke smart contract. We make this solution so adaptable that you don’t think about making any changes in the existing structure of the business. Our seasoned professionals help you get over all the problems that you might face in the planning or the execution stage. We make every single task absolutely flawless and help you get familiar with pragmatic fixes that are cost-effective too. If you want to make the most of this blockchain-based service, you must work with us.

Want an efficient smart contract for your business? Associate with us!

Contact Details:
Call and Whatsapp : +91-7014607737
Email: cryptodeveloperjaipur@gmail.com
Telegram : @vipinshar

#smart contract development company #smart contract #mlm smart contract #mlm #smart contract development #hire smart contract developer

Amara Sophi

Amara Sophi

1595917383

Top Smart Contract MLM Clone Scripts

Smart Contract MLM Software is a smart contract-based MLM platform, built on blockchain technology that helps you to build trustworthy blockchain MLM business with fully decentralized Ethereum SmartContract.The smart contract MLM has embedded with various working features of MLM Responsive Website, Member Back office, admin back office, secured cloud server, anti-DDOS protection, and SSL.

Benefits of Smart Contracts based MLM Platform

  • They are reliable since once programmed they cannot be reversed.
  • They are cost-effective since there will be no more transactional costs and the use of a huge amount of papers.
  • They are efficient since their processing speed is much higher than a traditional contract. They automatically enforce whatever is defined.
  • They are automatic and require no third party involvement.

Having an idea to start MLM business with smart contract development??

Coinjoker offers high end MLM software along with fresh business models, highly responsive and attractive UI/UX, and targeted MLM leads. This Smart contract-based MLM software is integrated with latest lead generating features to generate your passive income.

Some of the Smart Contract MLM Clone Scripts,

Million Money Clone Script

Millionmoney is a networking program that is built on blockchain technology and ethereum cryptocurrency as p2p donation among members. Million Money occurs to be a pyramid scheme, that is you have to pay a fee to join the scheme, and then you have to refer other people to that scheme. The only possible way to make a positive return on your original joining fee is to convince enough people to join after you. You will receive a small portion of the fees from any members who you recruit, while the rest of your fees get passed to higher levels of the pyramid.

Forsage Clone Script

Forsage, found at forsage.io, is a MLM or multi-level marketing company that claims to have created the world’s first 100% decentralized Ethereum smart contract.Forsage ethereum smart contract "enables peer-to-peer (P2P) commission payments between its program participants.” Forsage is Ethereum Blockchain Matrix Project, this smart contract is supposed to offer any participants “the ability to directly engage in personal and business transactions.

Doubleway Clone Script

Doubleway Multi-level marketing (MLM) is one of the most popular and easy way to make money online and other than the health and wellness niche, cryptocurrency seems to be one of the most-talked-about opportunities to start various mlm business in the wider globe space. Doubleway uses an MLM structured business model you can recruit new people to join doubleway through your affiliate link and build a downline team to earn commissions with the company.

Etrix Clone Script

Etrix is a First Smart Contract With Binary open MLM structure With Two Matrixes. It has Forced Matrix and Team Matrix. Both Team and Company Forced Matrixes are working simultaneously. Etrix is noted for the fastest and easiest way to earn ethereum for every 90 days. People are using this smart contract to give donations and receive donations in form of Ethereum.

XOXO Network Clone Script

XOXO Network is a decentralized, peer to peer global powerline networking system that runs on set protocols with no admin or official authority. This Ethereum smart contract-based system requires members to choose between different smart contract projects that could potentially yield profits. XOXO Network is nothing but a crypto-based cash gifting matrix cycler program. The Network uses Ethereum as the only method of payment that is member to member. Thus XOXO is the first-ever powerline network built on a smart contract, it protocols it’s unshakable and unstoppable to work and serve everyone equally.

You can launch the above mentioned smart contract-based MLM Clone scripts like Million Money, Forsage, Etrix, Doubleway, XOXO network within a week!!

Get Free Demo for Crypto MLM Clone Scripts>> https://www.cryptoexchangescript.com/contact-us

or contact through

Whatsapp ->> +91 9791703519

Skype->> live:support_60864

Telegram->> https://t.me/Coin_Joker

#smart contract based mlm clone #smart contract mlm clone script #smart contract based mlm clone script #smart contract mlm clone development #ethereum smart contract mlm clone script