Hacker Noon

Predicting a Crypto Summer in 2021

Predicting a Crypto Summer in 2021

Now is a good time to HODLSince early 2018, the cryptocurrency markets have fallen precipitously. As with previous crashes, many have claimed that the markets are unsalvageable and Bitcoin is dead. On the contrary, there is reason to believe that the c…

Why You Shouldn’t Start a Crypto Company

Why You Shouldn’t Start a Crypto Company

Why You Shouldn’t Start a Crypto Company

Imagine that you are a Soviet weight lifter. It’s the height of the Cold War. You’ve trained for years to crush the bourgeoisie on the battlefield of the Olympic podium, to bring back gold and glory to the motherland. One day your trainer pulls you aside and tells you that not only does he have access to performance-enhancing drugs developed for the Russian military, but also that all other Russian athletes are taking them, and that the USSR will help you hide the doping from international regulators.

This is the situation of most crypto startups today. On the fundraising and execution side, it is very, very easy to get ahead by playing fast and loose with compliance. It isn’t sustainable, but neither is prolonged drug abuse. When the lines aren’t clear, it’s very easy to slip across them.

In the early days of Carbon, we spent months assessing the viability of a token sale. It was at the height of the bull market for alts and our primary competitor, Basis, was knee deep in theirs. We ended up not moving forward as there wasn’t a clearly compliant option. Basis went on to raise 133M at a nearly billion dollar valuation. Their CEO made the Forbes 30 under 30 list and the startup was hailed as the golden child of crypto. A month later, Basis shut down and refunded what was left of the investors’ funds, due to concerns around compliance.

Basis did the right thing by shutting down. It took guts, especially after all the press, to admit that they were wrong. Many lesser men would have pivoted, redomiciled, or hired more attorneys tasked with the impossible task of forcing the square peg of Basis into the round hole of compliance. Many high-throughput chains seem to be taking the latter option. But Basis was willing to let go of the money which is a huge testament to the competence of their leadership team. (Basically, every competitor of theirs from that era has “pivoted” drastically and most still don’t have a clear path forward on compliance).

Unfortunately, crypto will likely be defined for the next few years by projects that will burn compliance to get ahead. Compliance is expensive and slow and, worst of all, ambiguous. Everyone will claim to be compliant but it will be essentially impossible to ascertain the validity of these claims. Investors generally won’t have the time or expertise to assess compliance so survival will likely end up being the proxy used there. We’ve found this to already be the case in crypto payments as the primary criticism of our feeless on off ramp being that “it’s new”). To top matters off, many crypto founders came out of less regulated sectors (crowdfunding, adtech, and gaming) where forgiveness was always cheaper than permission.

We have seen and will continue to see projects do “impossible” things only to learn later that they were about as far away from compliance as Uber is from profitability. Two companies will be in a rat race. One will break away by having no KYC, lowering fees (licenses are expensive), outraising through dubious token sales, launching products more quickly (legal opinions take time), and blatantly disregarding securities laws (as is in vogue in the stablecoin space). These groups aren’t burning the furniture: they’re burning the foundation and sloshing gasoline onto whatever’s left in the form of aggressive marketing.

Starting a crypto company, even if you have the best idea, is putting yourself in the position of the Russian weightlifter. Will you take steroids or watch a black and white television in Siberia while Boris from Chechnya crushes the capitalists?

The Path Forward

My advice to investors is to invest in both responsible founders and in compliance. For compliant (onshore) crypto companies, legal is often 30 to 50% of burn. Offering free legal resources to portfolio companies will lower the net burn rate, reduce the risk of companies engaging incompetent law firms, give the investor insight into the black box of compliance, and increase the rate of learning across the portfolio (what works for X should work for Y). As the sector matures investor’s legal teams will be well positioned to flag for regulators non-compliant competitors of their portfolio companies.

Most importantly, it diminishes pressure on portfolio companies to cheat. If lawyers are recommending delaying a launch, the founders are much more likely to acquiesce if the lawyers work for the investor rather than the company.

As both a payments company and capital markets actor, Carbon has found a niche that we’re comfortable with, on the sidelines of all the major races, where we can we try to help compliant companies get ahead. In fact, we generally try to notify our partners when products they may be interacting with are flagged by regulators.

As more companies collapse or get shut down compliance issues will be viewed as less of an act of god and more as a failure on the part of the founder and thereby a failure on the investor’s part. If a company seems like it’s doing something impossible on the regulatory front, it probably is. Eventually, the rest of the world caught Russia and banned the majority of their athletes from competing.

https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href


Why You Shouldn’t Start a Crypto Company was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

The Innards of an ERC20 Token

The Innards of an ERC20 Token

What does this mean?You’ve all heard by now that SunContract’s SNC token is an ERC20 token… But do you know what it means to be of ERC20 standard? If not, stick around for a simple explanation on the ERC20 standard.Ethereum PlatformERC20 tokens are des…

Are ICOs Completely Losing the Game to IEOs?

Are ICOs Completely Losing the Game to IEOs?

With Initial Exchange Offerings (IEOs) rapidly emerging as a popular crypto fundraising scheme, here a look into where the ICO market is heading.Since the beginning of 2019, the crypto funding terminology of Initial Exchange Offering (IEO) is buzzing a…

Developer’s Pack: The ONE Subscription

Developer’s Pack: The ONE Subscription

The ONE Subscription is a new service which offers thousands of pre-made products for websites building such as HTML templates and WordPress themes. The ONE will provide you with literally everything one could possibly imagine for building websites. Mo…

Upgrade Driven Development

Upgrade Driven Development

or: How I Learned to Stop Worrying and Love Immutable Code.Photo by Mike Tinnion on UnsplashAboutThis is a simplified overview of ideas regarding a design philosophy for developers building applications on the Ethereum blockchain. It builds upon many c…

Shamir Secret Sharing vs Multi-sig

Shamir Secret Sharing vs Multi-sig

After the beta launch of Coinsafe, many people asked me how does Shamir secret sharing compare to a multi-sig based approach for securing one’s crypto assets. I aim to articulate the pros and cons of each approach in this post.Part A : Shamir secret sh…

Why content, not tech, is king in podcasting

Why content, not tech, is king in podcasting

A look at Spotify’s recent acquisitions, and the upcoming launch of Luminary2019 has been an unprecedented year for exits in the podcast industry, driven by one company: Spotify. Spotify paid $340M to acquire content studio Gimlet and hosting platform …

Why We’re Going to Re-Architect Blockchain!

Why We’re Going to Re-Architect Blockchain!

a whole new world of possibility!•Blockchain for database storage. 😍Instead of storing data in native database forms we may use blockchain to store data which as a result becomes highly secure and decentralized(essence of blockchain).👉 In general, trad…

Testing React with jest, jest-axe, and react-testing-library

Testing React with jest, jest-axe, and react-testing-library

Testing React applications with jest, jest-axe, and react-testing-library

jest and react-testing-library logos

jest and react-testing-library are an increasingly used tooling pairing to test React components. We will briefly look at the differences between the two before looking at some high level examples, and how straightforward it is to add jest-axe to integrate aXe automated accessibility testing.

Jest

Jest is a JavaScript unit testing framework, developed by Facebook to test services and React applications.

jest acts as a test runner, assertion library, and mocking library.

jest also provides Snapshot testing, the ability to create a rendered ‘snapshot’ of a component and compare it to a previously saved ‘snapshot’. The test will fail if the two do not match. We will talk about the pros and cons of this later on.

Create React App comes bundled with Jest; it does not need to be installed separately.

React Testing Library

React Testing Library is a light-weight solution for testing React components. It provides utilities to facilitate querying the DOM in the same way the user would.

react-testing-library, created by Kent C. Dodds, adds utility methods for rendering a component (or multiple components), finding elements, and interacting with elements.

It is built on top of dom-testing-library and so includes all of its functionality.

It is possible, and encouraged, to be used alongside jest-dom. jest-dom is a companion library for react-testing-library that provides custom DOM element matchers for Jest such as toHaveTextContent or toBeVisible.

Both must be installed in addition to tools already bundled with Create React App.

Opinionated Testing Practices

react-testing-library is opinionated in its belief of good testing practices, and is a deliberate replacement for enzyme. react-testing-library‘s guiding principle is:

The more your tests resemble the way your software is used, the more confidence they can give you.

It believes that components should be tested by interacting with it as a user would, exposing several types of ByText queries to find elements by their text as a user would and so assert on what it finds.

It believes that enzyme‘s deeper API and shallow rendering abilities ‘encourage testing implementation details’ (such as State or internal method calls) which, as users are unaware of these details, produces false confidence in comparison to testing output and functionality.

Jest aXe

Custom Jest matcher for aXe for testing accessibility

Accessibility (a11y) of applications is much easier to get right if worked in from the start, rather than retroactively going back to try and fix. While the GDS Accessibility team found that only ~30% of issues are found by automated testing it can help to establish a baseline with virtually no effort to include and run.

It cannot and does not guarantee what we build is accessible, as it can only statically analyse code, but it provides a great start.

For full accessibility we’d also need to:

Jest and React Testing Library

  • Both Jest and React Testing Library are specifically designed to test React applications. Jest can be used with any other Javascript app but React Testing Library only works with React.
  • Jest can be used without React Testing Library to render components and test with snapshots, React Testing Library simply adds additional functionality.
  • React Testing Library can be used without Jest, however React Testing Library must be paired with another test runner if Jest is not used.

As described, we will use:

  • Jest as the test runner, assertion library, and mocking library
  • React Testing Library to provide additional testing utilities to interact with elements
  • Jest DOM to extend Jest with useful custom DOM element matchers
  • Jest aXe for automated accessibility testing

Setup

Installing and configuring

If not using Create React App (CRA) install jest:

npm install --save-dev jest babel-jest

Install react-testing-library, jest-dom, and jest-axe:

npm install --save-dev react-testing-library jest-dom jest-axe

This guide was written using jest@23.6.0, react-testing-library@6.1.2 , jest-dom@3.1.3 , and jest-axe@3.1.1.

Create a setupTests.js file at ./src/setupTests.js:

import 'jest-axe/extend-expect';
import 'jest-dom/extend-expect';
import 'react-testing-library/cleanup-after-each';

This allows for less code duplication in each test. Rather than importing the extend-expect‘s per test if put in the Jest-specific setupTests these are imported automatically before every test. In the same way cleanup-after-each calls afterEach(cleanup) after each test (used to help prevent memory leaks between tests) but only needs to be written once.

CRA will automatically pick up this file, if not using CRA then also add this line in the your package.json:

"jest": {
"setupFiles": ["./src/setupTests.js"],
}

Creating a test file

Jest will look for tests in any of the following places:

  • Files with .js suffix in __tests__ folders.
  • Files with .test.js suffix.
  • Files with .spec.js suffix.

It is convention to put each test file next to the code it is testing. This makes semantic sense, and also means relative paths are shorter ( ./MyComponent vs ../../MyComponent etc).

An example of this could be this MyComponent.test.jsfile:

import React from 'react';
import { render } from 'react-testing-library';
import MyComponent from './MyComponent';
describe('MyComponent', () => {
it('should render without crashing, () => {
const { container } = render(<MyComponent />);

expect(container).toHaveTextContent('Component Title');
});
});

When npm test in CRA is ran it will run all test files and output the results to the terminal. Customisation flags exist to run against specific files only, or conversely ignore specific files using — –testPathPattern filename/ and — –testPathIgnorePatterns filename/.

Testing

Basic component rendering

As seen in the example above components are rendered into a container that can then have expectations used on it.

const { container } = render(<MyComponent />);
expect(container).toHaveStyle('padding-top: 125px;');;

toHaveStyle is an example of a custom matcher from jest-dom. Others include toHaveTextContent and toBeVisible, with the full list seen in the jest-dom docs.

react-testing-library contains several query functions to find elements, which can be extracted when the component is rendered. These can be used to find elements and then perform actions on them, or to assert if elements are present based on if they can be found.

const { container, getByLabelText } = render(<MyComponent />);
expect(getByLabelText('some exact text')).toBeTruthy;

This syntax is different to the dom-testing-library that react-testing-library is based on and extends, where a query would be imported once per file, but need the rendered component passed in as a target each time a query was used.

// alternate approach not used in docs, requiring additional install
import { getByLabelText } from 'dom-testing-library';
...
const { container } = render(<MyComponent />);
expect(getByLabelText(container, 'some exact test')).toBeTruthy();

A cheatsheet can be seen in react-testing-library‘s docs.

These query functions and matchers allow us to test the functionality of the component based on what the user would actually see, rather than the implementation details beneath it.

Events

fireEvent is used to simulate user interaction, with several events available.

const element = getByText('Submit');
fireEvent.click(element);
// or say
fireEvent.keyDown(element, { key: 'Enter', code: 13 });

Mock functions

You may simply want to check that a function passed as props is successfully called.

const onClick = jest.fn();
const { container } = render(<MyComponent onClick={onClick} />);
const element = getByText('Submit');
fireEvent.click(element);
expect(onClick).toHaveBeenCalledTimes(1);

It is possible to use jest.fn().mockImplementation to mock the function in more detail if required.

Snapshot testing

Snapshot testing is a contentious topic. It is a fast way to test the full HTML output of a component, and so be able to see even the smallest of changes that any file change or dependency update may create.

However this depth is also its downside. In larger projects with many contributors, who may not understand the exact details of each component, developers are too tempted to automatically update them without inspecting the full change, as often this is a minor implementation detail that has changed. The value of the test is then drastically reduced, to the point many feel it provides false confidence and should not be used at all.

An expectation would look like:

expect(container).toMatchSnapshot();

Snapshots will be saved for you beside the test file that created them in an auto-generated __snapshots__ folder.

The decision to use snapshots or not is yours to make, and is specific to your project and your team.

Accessibility

Although we learned above that only ~30% of a11y issues can be found by automated testing, that is 30% more than no testing at all. Adding the below can assist with this.

import { axe } from 'jest-axe';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import MyComponent from './MyComponent';
it('should not have basic accessibility issues', async () => {
  const html = ReactDOMServer.renderToString(<MyComponent />);
  const results = await axe(html);    
  expect(results).toHaveNoViolations();    
});

Conclusion

jest, jest-dom, react-testing-library, and jest-axe work smoothly together to form a versatile testing toolkit for testing React components from a functional user perspective.

Whether this testing philosophy matches your own is only for you to decide, but hopefully this provides an entry point to seeing what is possible. The documentation of each is good and is linked in the resources section below.

Thanks for reading! 😊

If you liked this, you might also like:

Resources

If you are also wishing to look at visual regression testing in addition to unit and integration testing I can recommend looking to Differencify.

https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href


Testing React with jest, jest-axe, and react-testing-library was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

Writing Testable Code. Main Rules

Writing Testable Code. Main Rules

Every developer knows that the testable code can make life easier. There are a lot of books and articles written about unit-testing. Particular attention is paid to Test-driven development (TDD) as the best process for the development of hi-tech produc…

Trustlines are the new IOU

Trustlines are the new IOU

Trustlines are the new IOUsThe concept of debt first appeared in ancient times in the form of barter exchange. Later, when a monetary system emerged, it became an integral part of the financial system, and new kinds of debt obligations came into existe…

The Mindset Of The Startup Founders

The Mindset Of The Startup Founders

What Goes Into The Mind Of Startup Founders?Idea is powerful but not until it becomes actionable and get the validation by real user.We are living in the era where the word impossible seems to be challenged by young dare-devils. For them every problem …

Is React Native Worth Using?

Is React Native Worth Using?

React Native provides an opportunity to build cross-platform apps for both IOS and Android. This creates a thought that you can build one app that will work on both platforms, so you can cut the costs twice. However, there is a lot of misconception aro…