Skip to content

Commit

Permalink
Merge pull request #95 from MinterTeam/toronet
Browse files Browse the repository at this point in the history
add vote update tx
  • Loading branch information
grkamil authored Apr 18, 2022
2 parents 8846832 + 78a053b commit 4cdc179
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Minter/SDK/MinterCoins/MinterCoinTx.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ abstract class MinterCoinTx implements MinterTxInterface
MinterMoveStakeTx::TYPE => MinterMoveStakeTx::class,
MinterLockStakeTx::TYPE => MinterLockStakeTx::class,
MinterLockTx::TYPE => MinterLockTx::class,
MinterVoteUpdateTx::TYPE => MinterVoteUpdateTx::class,
];

/**
Expand Down
53 changes: 53 additions & 0 deletions src/Minter/SDK/MinterCoins/MinterVoteUpdateTx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Minter\SDK\MinterCoins;

use Minter\Contracts\MinterTxInterface;
use Minter\Library\Helper;
use Minter\SDK\MinterPrefix;

/**
* Class MinterVoteUpdateTx
* @package Minter\SDK\MinterCoins
*/
class MinterVoteUpdateTx extends MinterCoinTx implements MinterTxInterface
{
public $publicKey;
public $version;
public $height;

const TYPE = 33;

/**
* @param $version
* @param $publicKey
* @param $height
*/
public function __construct($version, $publicKey, $height)
{
$this->publicKey = $publicKey;
$this->version = $version;
$this->height = $height;
}

/**
* Prepare data for signing
*
* @return array
*/
public function encodeData(): array
{
return [
$this->version,
hex2bin(Helper::removePrefix($this->publicKey, MinterPrefix::PUBLIC_KEY)),
$this->height
];
}

public function decodeData()
{
$this->publicKey = MinterPrefix::PUBLIC_KEY . $this->publicKey;
$this->height = hexdec($this->height);
$this->version = Helper::hex2str($this->version);
}
}
3 changes: 2 additions & 1 deletion src/Minter/SDK/MinterTx.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use Minter\SDK\MinterCoins\MinterSetCandidateOnTx;
use Minter\SDK\MinterCoins\MinterSetHaltBlockTx;
use Minter\SDK\MinterCoins\MinterUnbondTx;
use Minter\SDK\MinterCoins\MinterVoteUpdateTx;
use Web3p\RLP\RLP;;
use Minter\Library\Helper;
use Minter\SDK\MinterCoins\MinterCoinTx;
Expand Down Expand Up @@ -375,7 +376,7 @@ public function getSignatureData(): MinterSignature
}

/**
* @return MinterSendCoinTx|MinterBuyCoinTx|MinterSellCoinTx|MinterSellAllCoinTx|MinterDelegateTx|MinterUnbondTx|MinterMultiSendTx|MinterCreateMultisigTx|MinterCreateCoinTx|MinterRecreateCoinTx|MinterEditCoinOwnerTx|MinterDeclareCandidacyTx|MinterSetCandidateOnTx|MinterSetCandidateOffTx|MinterEditCandidateTx|MinterRedeemCheckTx|MinterSetHaltBlockTx|MinterSellSwapPoolTx|MinterSellAllSwapPoolTx|MinterBuySwapPoolTx|MinterPriceCommissionTx|MinterCreateTokenTx|MinterRecreateTokenTx|MinterCreateSwapPoolTx|MinterBurnTokenTx|MinterMintTokenTx|MinterAddLiquidityTx|MinterRemoveLiquidityTx|MinterAddLimitOrderTx|MinterRemoveLimitOrderTx|MinterLockTx|MinterLockStakeTx|MinterMoveStakeTx
* @return MinterSendCoinTx|MinterBuyCoinTx|MinterSellCoinTx|MinterSellAllCoinTx|MinterDelegateTx|MinterUnbondTx|MinterMultiSendTx|MinterCreateMultisigTx|MinterCreateCoinTx|MinterRecreateCoinTx|MinterEditCoinOwnerTx|MinterDeclareCandidacyTx|MinterSetCandidateOnTx|MinterSetCandidateOffTx|MinterEditCandidateTx|MinterRedeemCheckTx|MinterSetHaltBlockTx|MinterSellSwapPoolTx|MinterSellAllSwapPoolTx|MinterBuySwapPoolTx|MinterPriceCommissionTx|MinterCreateTokenTx|MinterRecreateTokenTx|MinterCreateSwapPoolTx|MinterBurnTokenTx|MinterMintTokenTx|MinterAddLiquidityTx|MinterRemoveLiquidityTx|MinterAddLimitOrderTx|MinterRemoveLimitOrderTx|MinterLockTx|MinterLockStakeTx|MinterMoveStakeTx|MinterVoteUpdateTx
*/
public function getData(): MinterTxInterface
{
Expand Down
68 changes: 68 additions & 0 deletions tests/MinterVoteUpdateTxTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);

use Minter\SDK\MinterCoins\MinterVoteUpdateTx;
use Minter\SDK\MinterTx;
use PHPUnit\Framework\TestCase;

/**
* Class for testing MinterVoteUpdateTxTest
*/
final class MinterVoteUpdateTxTest extends TestCase
{
/**
* Predefined private key
*/
const PRIVATE_KEY = '0x9f444c46ea729be713ac1c5bc3390e2dca61ca288c59356fce44165aaae9184a';

/**
* Predefined minter address
*/
const MINTER_ADDRESS = 'Mx522ce8622d7cb5cac0a03fd7e4b76a8586813cd9';

/**
* Predefined valid signature
*/
const VALID_SIGNATURE = '0xf87c0102018021aceb8474657374a0d83e627510eea6aefa46d9914b0715dabf4a561ced78d34267b31d41d5f700b58405f5e0ff808001b845f8431ca0031ea17f1af0cc678f978db4dc5b0419b09d40ef99a480cb8aba7688fcf1083da003632fd34b944ad0b630124df95d26ea5a6c2a4d1890942a670390d3f1811da0';

/**
* Test to decode data for MinterVoteUpdateTx
*/
public function testDecode(): void
{
$tx = MinterTx::decode(self::VALID_SIGNATURE);
$validTx = $this->makeTransaction();

$this->assertSame($validTx->getNonce(), $tx->getNonce());
$this->assertSame($validTx->getGasCoin(), $tx->getGasCoin());
$this->assertSame($validTx->getGasPrice(), $tx->getGasPrice());
$this->assertSame($validTx->getChainID(), $tx->getChainID());
$this->assertSame($validTx->getData()->publicKey, $tx->getData()->publicKey);
$this->assertSame($validTx->getData()->version, $tx->getData()->version);
$this->assertSame($validTx->getData()->height, $tx->getData()->height);
$this->assertSame(self::MINTER_ADDRESS, $tx->getSenderAddress());
}

/**
* Test signing MinterUnbondTx
*/
public function testSign(): void
{
$signature = $this->makeTransaction()->sign(self::PRIVATE_KEY);
$this->assertSame($signature, self::VALID_SIGNATURE);
}

/**
* @return MinterTx
*/
private function makeTransaction(): MinterTx
{
$data = new MinterVoteUpdateTx(
'test',
'Mpd83e627510eea6aefa46d9914b0715dabf4a561ced78d34267b31d41d5f700b5',
99999999, '100'
);

return (new MinterTx(1, $data))->setTestnetChainId();
}
}

0 comments on commit 4cdc179

Please sign in to comment.