Skip to content

Commit

Permalink
style: add editorconfig and format files
Browse files Browse the repository at this point in the history
  • Loading branch information
recanman committed Aug 3, 2024
1 parent 43f11ad commit b2831a5
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 89 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[root]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_size = 4
indent_style = tab
trim_trailing_whitespace = true
10 changes: 5 additions & 5 deletions src/Base58.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static function decToHex(BigInteger $dec): string
while (!$dec->equals(0)) {
$remainder = $dec->mod(16);
$dec = $dec->div(16);
$res = dechex((int)$remainder->toDec()).$res;
$res = dechex((int)$remainder->toDec()) . $res;
}

return $res;
Expand All @@ -58,7 +58,7 @@ private static function encodeBlock(array $data, array $res, int $res_offset): a
$length = count($data);

if ($length < 1 || $length > self::FULL_ENCODED_BLOCK_SIZE) {
throw new Exception("Invalid block length: ". $length);
throw new Exception("Invalid block length: " . $length);
}

$num = self::uint8beTo64($data);
Expand Down Expand Up @@ -115,7 +115,7 @@ private static function decodeBlock(array $data, array $res): array
$length = count($data);

if ($length < 1 || $length > self::FULL_ENCODED_BLOCK_SIZE) {
throw new Exception("Invalid block length: ". $length);
throw new Exception("Invalid block length: " . $length);
}

$num = new BigInteger(0);
Expand All @@ -125,7 +125,7 @@ private static function decodeBlock(array $data, array $res): array
$char_value = strpos(self::ALPHABET, $char);

if ($char_value === false) {
throw new Exception("Invalid character: ". $char);
throw new Exception("Invalid character: " . $char);
}

$num = $num->mul(self::ALPHABET_SIZE)->add($char_value);
Expand Down Expand Up @@ -161,4 +161,4 @@ public static function decode(string $base58): string

return bin2hex(implode('', $res));
}
}
}
2 changes: 1 addition & 1 deletion src/wordsets/portuguese.ws.php
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,6 @@ public static function words(): array
"zeloso",
"zenite",
"zumbi"
];
];
}
}
3 changes: 1 addition & 2 deletions src/wordsets/russian.ws.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class russian implements Wordset
public static function name(): string
{
return "русский язык";

}

/**
Expand Down Expand Up @@ -1674,6 +1673,6 @@ public static function words(): array
"яхта",
"ячейка",
"ящик"
];
];
}
}
1 change: 0 additions & 1 deletion src/wordsets/spanish.ws.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class spanish implements Wordset
public static function name(): string
{
return "Español";

}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Base58Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Base58Test extends TestCase
public function testEncode()
{
$this->assertSame($this->testEncoded, Base58::encode($this->testDecoded));

$this->expectException(TypeError::class);
Base58::encode("invalid");
}
Expand Down
147 changes: 68 additions & 79 deletions tests/unit/CryptonoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,89 +8,78 @@

class CryptonoteTest extends TestCase
{
private $testDecodedKeccak = "6fd43e7cffc31bb581d7421c8698e29aa2bd8e7186a394b85299908b4eb9b175";
private $testEncodedKeccak = "0b6a7d8d740055460014f9c3e31063c5bb8e254cb9fee970294a0d0064429ca8";

private $testHexSeed = "92df69221844dc2a77389e2c3ebae5fa32517c04826c870fb952171fb192cc08";
private $testPubViewKey = "a21d0a8ceacdb5e6a5d8bba57741123671c83a3b34187fe23324112b0c7b7760";
private $testPrivateViewKey = "e7cbc9050333b9ed07843ce835547c07c8a8d6b7acc10bebb60d7d6fe1a82f05";
private $testPubSpendKey = "765d0b9d61e8ca67b8902f6b133ae7bcdde5419c72ab6244ed7400789db7be99";
private $testPrivateSpendKey = "92df69221844dc2a77389e2c3ebae5fa32517c04826c870fb952171fb192cc08";

private $testAddressNetByte = "12";
private $testAddress = "467GHbWjuFoJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cBu3mLYj";
private $testAddressBad = "467GHbWjuFoJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cBu3mLzj";

private $testPaymentId = "ef64f0a81b022a81";
private $testIntegratedAddress = "4FowJQLEWXKJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cHDPkStRLntqFZqGwKS";

/** @var Cryptonote */
private $cr;

public function setUp(): void
{
$this->cr = new Cryptonote(MoneroNetwork::mainnet);
}

public function testKeccak256(): void
{
$result = $this->cr->keccak_256($this->testDecodedKeccak);
$this->assertEquals($this->testEncodedKeccak, $result);
}

public function testGenNewHexSeed(): void
{
$result = $this->cr->gen_new_hex_seed();
$this->assertIsString($result);
$this->assertEquals(64, strlen($result));
}

// public function testDeriveViewKey(): void
// {
// $result = $this->cr->derive_viewKey($this->testPrivateSpendKey);
// $this->assertEquals($this->testPrivateViewKey, $result);
// }
private $testDecodedKeccak = "6fd43e7cffc31bb581d7421c8698e29aa2bd8e7186a394b85299908b4eb9b175";
private $testEncodedKeccak = "0b6a7d8d740055460014f9c3e31063c5bb8e254cb9fee970294a0d0064429ca8";

private $testHexSeed = "92df69221844dc2a77389e2c3ebae5fa32517c04826c870fb952171fb192cc08";
private $testPubViewKey = "a21d0a8ceacdb5e6a5d8bba57741123671c83a3b34187fe23324112b0c7b7760";
private $testPrivateViewKey = "e7cbc9050333b9ed07843ce835547c07c8a8d6b7acc10bebb60d7d6fe1a82f05";
private $testPubSpendKey = "765d0b9d61e8ca67b8902f6b133ae7bcdde5419c72ab6244ed7400789db7be99";
private $testPrivateSpendKey = "282a30d36de33cc65eb7804126a7644c2cce00ce2aac171a7c24496ba2764701";

private $testAddressNetByte = "12";
private $testAddress = "467GHbWjuFoJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cBu3mLYj";
private $testAddressBad = "467GHbWjuFoJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cBu3mLzj";

private $testPaymentId = "ef64f0a81b022a81";
private $testIntegratedAddress = "4FowJQLEWXKJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cHDPkStRLntqFZqGwKS";

/** @var Cryptonote */
private $cr;

public function setUp(): void
{
$this->cr = new Cryptonote(MoneroNetwork::mainnet);
}

public function testKeccak256(): void
{
$result = Cryptonote::keccak_256($this->testDecodedKeccak);
$this->assertEquals($this->testEncodedKeccak, $result);
}

public function testGenNewHexSeed(): void
{
$result = $this->cr->gen_new_hex_seed();
$this->assertIsString($result);
$this->assertEquals(64, strlen($result));
}

public function testScReduce(): void
{
$result = $this->cr->sc_reduce("65");
$this->assertEquals("65", $result);
}

public function testEncodeAddress(): void
{
$result = $this->cr->encode_address($this->testPubSpendKey, $this->testPubViewKey);
$this->assertEquals($this->testAddress, $result);
}

public function testVerifyChecksum(): void
{
$result = $this->cr->verify_checksum($this->testAddress);
$this->assertTrue($result);

$result = $this->cr->verify_checksum($this->testAddressBad);
$this->assertFalse($result);
}

public function testDecodeAddress(): void
{
$result = $this->cr->decode_address($this->testAddress);
$this->assertIsArray($result);

$this->assertEquals($this->testAddressNetByte, $result["networkByte"]);
$this->assertEquals($this->testPubSpendKey, $result["spendKey"]);
$this->assertEquals($this->testPubViewKey, $result["viewKey"]);
}

public function testIntegratedAddrFromKeys(): void
{
$result = $this->cr->integrated_addr_from_keys($this->testPubSpendKey, $this->testPubViewKey, $this->testPaymentId);
$this->assertEquals($this->testIntegratedAddress, $result);
}

// public function testAddressFromSeed(): void
// {
// $result = $this->cr->address_from_seed($this->testHexSeed);
// $this->assertEquals($this->testAddress, $result);
// }
}

public function testEncodeAddress(): void
{
$result = $this->cr->encode_address($this->testPubSpendKey, $this->testPubViewKey);
$this->assertEquals($this->testAddress, $result);
}

public function testVerifyChecksum(): void
{
$result = $this->cr->verify_checksum($this->testAddress);
$this->assertTrue($result);

$result = $this->cr->verify_checksum($this->testAddressBad);
$this->assertFalse($result);
}

public function testDecodeAddress(): void
{
$result = $this->cr->decode_address($this->testAddress);
$this->assertIsArray($result);

$this->assertEquals($this->testAddressNetByte, $result["networkByte"]);
$this->assertEquals($this->testPubSpendKey, $result["spendKey"]);
$this->assertEquals($this->testPubViewKey, $result["viewKey"]);
}

public function testIntegratedAddrFromKeys(): void
{
$result = $this->cr->integrated_addr_from_keys($this->testPubSpendKey, $this->testPubViewKey, $this->testPaymentId);
$this->assertEquals($this->testIntegratedAddress, $result);
}
}

0 comments on commit b2831a5

Please sign in to comment.