Exemple #1
0
        public void Each_account_can_sign_with_simple_key(DevWalletType walletType)
        {
            IWallet wallet = SetupWallet(walletType);

            for (int i = 1; i <= (walletType == DevWalletType.Memory ? 10 : 3); i++)
            {
                byte[] keyBytes = new byte[32];
                keyBytes[31] = (byte)i;
                PrivateKey key = new PrivateKey(keyBytes);
                Assert.AreEqual(key.Address, wallet.GetAccounts()[i - 1], $"{i}");
            }
        }
        public void Each_account_can_sign_with_simple_key(DevWalletType walletType)
        {
            IWallet wallet = SetupWallet(walletType);

            int count = walletType == DevWalletType.Memory ? 10 : 3;

            for (int i = 1; i <= count; i++)
            {
                byte[] keyBytes = new byte[32];
                keyBytes[31] = (byte)i;
                PrivateKey key = new PrivateKey(keyBytes);
                TestContext.Write(key.Address.Bytes.ToHexString() + Environment.NewLine);
                Assert.True(wallet.GetAccounts().Any(a => a == key.Address), $"{i}");
            }

            Assert.AreEqual(count, wallet.GetAccounts().Length);
        }
        public void Can_sign_on_networks_with_chain_id(DevWalletType walletType, int chainId)
        {
            EthereumEcdsa ecdsa  = new EthereumEcdsa(chainId, LimboLogs.Instance);
            IWallet       wallet = SetupWallet(walletType);

            for (int i = 1; i <= (walletType == DevWalletType.Memory ? 10 : 3); i++)
            {
                Address     signerAddress = wallet.GetAccounts()[0];
                Transaction tx            = new Transaction();
                tx.SenderAddress = signerAddress;

                wallet.Sign(tx, chainId);
                Address recovered = ecdsa.RecoverAddress(tx);
                Assert.AreEqual(signerAddress, recovered, $"{i}");
                Assert.AreEqual(chainId, tx.Signature.ChainId, "chainId");
            }
        }
        public void Can_sign_on_networks_with_chain_id(DevWalletType walletType)
        {
            const int     networkId = 40000;
            EthereumEcdsa ecdsa     = new EthereumEcdsa(new SingleReleaseSpecProvider(Latest.Release, networkId), NullLogManager.Instance);
            IWallet       wallet    = SetupWallet(walletType);

            for (int i = 1; i <= (walletType == DevWalletType.Memory ? 10 : 3); i++)
            {
                Address     signerAddress = wallet.GetAccounts()[0];
                Transaction tx            = new Transaction();
                tx.SenderAddress = signerAddress;

                wallet.Sign(tx, networkId);
                Address recovered = ecdsa.RecoverAddress(tx, networkId);
                Assert.AreEqual(signerAddress, recovered, $"{i}");
                Assert.AreEqual(networkId, tx.Signature.ChainId, "chainId");
            }
        }
        private IWallet SetupWallet(DevWalletType devWalletType)
        {
            switch (devWalletType)
            {
            case DevWalletType.KeyStore:
                IKeyStoreConfig config = new KeyStoreConfig();
                config.KeyStoreDirectory = _keyStorePath;
                ISymmetricEncrypter encrypter = new AesEncrypter(config, LimboLogs.Instance);
                return(new DevKeyStoreWallet(
                           new FileKeyStore(config, new EthereumJsonSerializer(), encrypter, new CryptoRandom(), LimboLogs.Instance),
                           LimboLogs.Instance));

            case DevWalletType.Memory:
                return(new DevWallet(new WalletConfig(), LimboLogs.Instance));

            default:
                throw new ArgumentOutOfRangeException(nameof(devWalletType), devWalletType, null);
            }
        }
        public void Has_10_dev_accounts(DevWalletType walletType)
        {
            IWallet wallet = SetupWallet(walletType);

            Assert.AreEqual((walletType == DevWalletType.Memory ? 10 : 3), wallet.GetAccounts().Length);
        }
 public void Can_setup_wallet_twice(DevWalletType walletType)
 {
     IWallet wallet1 = SetupWallet(walletType);
     IWallet wallet2 = SetupWallet(walletType);
 }