-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from MinterTeam/toronet
add vote update tx
- Loading branch information
Showing
4 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |