Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ In `StateMachine.sol`:
* constructor: Creates the setup state and updates currentState to it.

* function `stateExists(bytes32 _state)`: Returns `true` if `_state` exists.
* function `createState(bytes32 _state`: Adds a new state with id `_state` to the contract. There is no function to remove states.
* function `createTransition(bytes32 _originState, bytes32 _targetState)`: Adds a transition from `_originState` to `_targetState`.
* function `transition(bytes32 _targetState)`: Transitions the machine from `currentState` to `_targetState`.
* function `_createState(bytes32 _state`: Adds a new state with id `_state` to the contract. There is no function to remove states.
* function `_createTransition(bytes32 _originState, bytes32 _targetState)`: Adds a transition from `_originState` to `_targetState`.
* function `_transition(bytes32 _targetState)`: Transitions the machine from `currentState` to `_targetState`.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ contract StateMachine {
/**
* @dev Create a new state.
*/
function createState(bytes32 _state)
public
function _createState(bytes32 _state)
internal
{
require(currentState == SETUP_STATE, "State machine not in SETUP.");
require(!stateExists(_state), "State already exists.");
Expand All @@ -71,8 +71,8 @@ contract StateMachine {
/**
* @dev Create a transition between two states.
*/
function createTransition(bytes32 _originState, bytes32 _targetState)
public
function _createTransition(bytes32 _originState, bytes32 _targetState)
internal
{
require(currentState == SETUP_STATE, "State machine not in SETUP.");
require(stateExists(_originState), "Origin state doesn't exist.");
Expand All @@ -85,8 +85,8 @@ contract StateMachine {
/**
* @dev Transition the state machine between states
*/
function transition(bytes32 _targetState)
public
function _transition(bytes32 _targetState)
internal
{
require(stateExists(_targetState), "Target state doesn't exist.");
State memory originState = states[currentState];
Expand Down
23 changes: 23 additions & 0 deletions contracts/state/TestStateMachine.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity ^0.5.10;

import "./StateMachine.sol";


contract TestStateMachine is StateMachine {

function createState(bytes32 _state) external {
_createState(_state);
}

function createTransition(
bytes32 _originState,
bytes32 _targetState
) external {
_createTransition(_originState, _targetState);
}

function transition(bytes32 _targetState) external {
_transition(_targetState);
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { should } from 'chai';
import { StateMachineInstance } from '../../../types/truffle-contracts';
import { TestStateMachineInstance } from '../../types/truffle-contracts';

const StateMachine = artifacts.require('./state/StateMachine.sol') as Truffle.Contract<StateMachineInstance>;
const StateMachine = artifacts.require('./state/TestStateMachine.sol') as Truffle.Contract<TestStateMachineInstance>;
should();

// tslint:disable-next-line no-var-requires
const { itShouldThrow } = require('./../../utils');
const { itShouldThrow } = require('./../utils');

contract('StateMachine', (accounts) => {
let stateMachine: StateMachineInstance;
contract('TestStateMachine', (accounts) => {
let stateMachine: TestStateMachineInstance;
const SETUP_STATE = 'SETUP';
const NEW_STATE = 'NEW';

Expand Down
Loading