Skip to main content

Testing Functions

The EVVM contract includes specialized functions designed specifically for testnet environments. These functions provide convenient ways to set up test scenarios, distribute test tokens, and configure staker statuses for development and testing purposes.

Testnet Only

These functions are intended for testnet use only and should not be available in production deployments. They provide unrestricted access to balance and staker configuration for testing convenience.


Balance Testing Functions

addBalance

Function Type: external
Function Signature: addBalance(address,address,uint256)

Faucet function that adds balance to a user's account for testing purposes. This function provides an easy way to distribute test tokens to users without requiring complex deposit processes.

Input Parameters

ParameterTypeDescription
useraddressAddress of the user to receive the balance
tokenaddressAddress of the token contract to add balance for
quantityuint256Amount of tokens to add to the user's balance

Testing Features

  • No Access Control: Anyone can call this function on testnet
  • Unlimited Distribution: No limits on amount or frequency
  • Multi-Token Support: Works with any token address
  • Immediate Effect: Balance is added instantly

Use Cases

  • Test Setup: Quickly provide users with test tokens
  • Scenario Testing: Create specific balance conditions for testing
  • Developer Convenience: Skip complex deposit processes during development
  • Integration Testing: Simulate various balance states

Example Usage

// Give a user 1000 MATE tokens for testing
evvm.addBalance(testUserAddress, mateTokenAddress, 1000 * 10**18);

// Give a user 500 USDC for testing payments
evvm.addBalance(testUserAddress, usdcTokenAddress, 500 * 10**6);

Staker Testing Functions

setPointStaker

Function Type: external
Function Signature: setPointStaker(address,bytes1)

Faucet function that configures staker status for testing purposes. This function allows developers to quickly set up staker configurations without going through the full staking process.

Input Parameters

ParameterTypeDescription
useraddressAddress of the user to set as point staker
answerbytes1Bytes1 value representing the staker status/type

Staker Status Values

ValueDescription
0x01Standard staker status (FLAG_IS_STAKER)
0x00Non-staker status
Other valuesCustom staker types or configurations

Testing Features

  • No Access Control: Anyone can call this function on testnet
  • Instant Configuration: Bypasses normal staking contract validation
  • Flexible Status: Supports various staker configurations
  • Development Convenience: Quickly test staker-specific functionality

Use Cases

  • Staker Testing: Test staker-specific payment functions and rewards
  • Permission Testing: Verify staker privilege systems
  • Integration Testing: Test interactions between stakers and non-stakers
  • Scenario Creation: Set up complex multi-user staking scenarios

Example Usage

// Set a user as a staker for testing
evvm.setPointStaker(testUserAddress, 0x01);

// Remove staker status from a user
evvm.setPointStaker(testUserAddress, 0x00);

// Set custom staker configuration
evvm.setPointStaker(testUserAddress, customStatusByte);

Testing Workflow Integration

Complete Test Setup

// 1. Set up a test user as a staker
evvm.setPointStaker(testUser, 0x01);

// 2. Provide test tokens
evvm.addBalance(testUser, mateTokenAddress, 10000 * 10**18);
evvm.addBalance(testUser, usdcTokenAddress, 1000 * 10**6);

// 3. Now test user can process staker payments and receive rewards

Multi-User Test Scenarios

// Set up multiple test users with different configurations
address[] testUsers = [user1, user2, user3];

// User 1: Staker with high balance
evvm.setPointStaker(testUsers[0], 0x01);
evvm.addBalance(testUsers[0], mateTokenAddress, 50000 * 10**18);

// User 2: Non-staker with moderate balance
evvm.setPointStaker(testUsers[1], 0x00);
evvm.addBalance(testUsers[1], mateTokenAddress, 1000 * 10**18);

// User 3: Staker with low balance
evvm.setPointStaker(testUsers[2], 0x01);
evvm.addBalance(testUsers[2], mateTokenAddress, 100 * 10**18);

Security Considerations for Production

Function Removal

  • These functions should be removed or disabled in production deployments
  • Consider using compiler flags or deployment-time configuration
  • Implement proper access controls if testing functions must remain

Alternative Testing Approaches

For production-ready testing:

// Use proper staking contract integration
stakingContract.stake(amount);

// Use treasury for balance management
treasury.deposit(token, amount);

// Use proper signature-based payments
evvm.payStaker_sync(..., signature);

Testing Environment Isolation

  • Maintain clear separation between testing and production environments
  • Use different contract deployments for different environments
  • Implement proper CI/CD pipelines with environment-specific configurations

Development Best Practices

Test Automation

// Example test setup in JavaScript/TypeScript
async function setupTestEnvironment() {
// Deploy contracts with testing functions enabled
const evvm = await deployEVVM({ testingMode: true });

// Set up test users
await evvm.setPointStaker(testUser1.address, "0x01");
await evvm.addBalance(testUser1.address, mateToken.address, parseEther("10000"));

return { evvm, testUsers: [testUser1] };
}

Clean Test States

// Reset balances between tests
async function resetTestUser(userAddress) {
const balance = await evvm.getBalance(userAddress, mateToken.address);
if (balance > 0) {
// Note: In production, implement proper balance reset mechanism
await evvm.addBalance(userAddress, mateToken.address, balance.mul(-1));
}
await evvm.setPointStaker(userAddress, "0x00");
}