From 5155052d046d6770d9aec23e6a7cd47475276dfe Mon Sep 17 00:00:00 2001 From: Eason Smith Date: Fri, 13 Dec 2024 14:59:12 +0800 Subject: [PATCH 1/2] deploy mock USDT smart contract and test ERC20 contract transfer --- .../ethereum/contracts/usdt/contract.json | 534 ++++++++++++++++++ networks/ethereum/devnet/README.md | 12 +- .../ethereum/devnet/__tests__/ethers.test.ts | 71 +++ .../ethereum/devnet/__tests__/send.test.ts | 41 -- networks/ethereum/devnet/run-ganache.sh | 5 + networks/ethereum/package.json | 7 +- 6 files changed, 626 insertions(+), 44 deletions(-) create mode 100644 networks/ethereum/contracts/usdt/contract.json create mode 100644 networks/ethereum/devnet/__tests__/ethers.test.ts delete mode 100644 networks/ethereum/devnet/__tests__/send.test.ts create mode 100644 networks/ethereum/devnet/run-ganache.sh diff --git a/networks/ethereum/contracts/usdt/contract.json b/networks/ethereum/contracts/usdt/contract.json new file mode 100644 index 00000000..534b25aa --- /dev/null +++ b/networks/ethereum/contracts/usdt/contract.json @@ -0,0 +1,534 @@ +{ + "_format": "hh-sol-artifact-1", + "contractName": "USDT", + "sourceName": "contracts/USDT.sol", + "abi": [ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "ECDSAInvalidSignature", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "ECDSAInvalidSignatureLength", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "ECDSAInvalidSignatureS", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "allowance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "needed", + "type": "uint256" + } + ], + "name": "ERC20InsufficientAllowance", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "balance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "needed", + "type": "uint256" + } + ], + "name": "ERC20InsufficientBalance", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "approver", + "type": "address" + } + ], + "name": "ERC20InvalidApprover", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "ERC20InvalidReceiver", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "ERC20InvalidSender", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "ERC20InvalidSpender", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "ERC2612ExpiredSignature", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "signer", + "type": "address" + }, + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "ERC2612InvalidSigner", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint256", + "name": "currentNonce", + "type": "uint256" + } + ], + "name": "InvalidAccountNonce", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidShortString", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "str", + "type": "string" + } + ], + "name": "StringTooLong", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "EIP712DomainChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "eip712Domain", + "outputs": [ + { + "internalType": "bytes1", + "name": "fields", + "type": "bytes1" + }, + { + "internalType": "string", + "name": "name", + "type": "string" + }, + { + "internalType": "string", + "name": "version", + "type": "string" + }, + { + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "verifyingContract", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "salt", + "type": "bytes32" + }, + { + "internalType": "uint256[]", + "name": "extensions", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "nonces", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "bytecode": "0x61016060405234801561001157600080fd5b506040518060400160405280600481526020017f5553445400000000000000000000000000000000000000000000000000000000815250806040518060400160405280600181526020017f31000000000000000000000000000000000000000000000000000000000000008152506040518060400160405280600981526020017f4d6f636b205553445400000000000000000000000000000000000000000000008152506040518060400160405280600481526020017f555344540000000000000000000000000000000000000000000000000000000081525081600390816100fa9190610819565b50806004908161010a9190610819565b5050506101216005836101f660201b90919060201c565b610120818152505061013d6006826101f660201b90919060201c565b6101408181525050818051906020012060e08181525050808051906020012061010081815250504660a0818152505061017a61024660201b60201c565b608081815250503073ffffffffffffffffffffffffffffffffffffffff1660c08173ffffffffffffffffffffffffffffffffffffffff16815250505050506101f1336101ca6102a160201b60201c565b600a6101d69190610a5a565b6402540be4006101e69190610aa5565b6102aa60201b60201c565b610d82565b6000602083511015610218576102118361033260201b60201c565b9050610240565b826102288361039a60201b60201c565b60000190816102379190610819565b5060ff60001b90505b92915050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60e051610100514630604051602001610286959493929190610b50565b60405160208183030381529060405280519060200120905090565b60006012905090565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160361031c5760006040517fec442f050000000000000000000000000000000000000000000000000000000081526004016103139190610ba3565b60405180910390fd5b61032e600083836103a460201b60201c565b5050565b600080829050601f8151111561037f57826040517f305a27a90000000000000000000000000000000000000000000000000000000081526004016103769190610c43565b60405180910390fd5b80518161038b90610c95565b60001c1760001b915050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036103f65780600260008282546103ea9190610cfc565b925050819055506104c9565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610482578381836040517fe450d38c00000000000000000000000000000000000000000000000000000000815260040161047993929190610d30565b60405180910390fd5b8181036000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610512578060026000828254039250508190555061055f565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055505b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516105bc9190610d67565b60405180910390a3505050565b600081519050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061064a57607f821691505b60208210810361065d5761065c610603565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b6000600883026106c57fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82610688565b6106cf8683610688565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b600061071661071161070c846106e7565b6106f1565b6106e7565b9050919050565b6000819050919050565b610730836106fb565b61074461073c8261071d565b848454610695565b825550505050565b600090565b61075961074c565b610764818484610727565b505050565b5b818110156107885761077d600082610751565b60018101905061076a565b5050565b601f8211156107cd5761079e81610663565b6107a784610678565b810160208510156107b6578190505b6107ca6107c285610678565b830182610769565b50505b505050565b600082821c905092915050565b60006107f0600019846008026107d2565b1980831691505092915050565b600061080983836107df565b9150826002028217905092915050565b610822826105c9565b67ffffffffffffffff81111561083b5761083a6105d4565b5b6108458254610632565b61085082828561078c565b600060209050601f8311600181146108835760008415610871578287015190505b61087b85826107fd565b8655506108e3565b601f19841661089186610663565b60005b828110156108b957848901518255600182019150602085019450602081019050610894565b868310156108d657848901516108d2601f8916826107df565b8355505b6001600288020188555050505b505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008160011c9050919050565b6000808291508390505b60018511156109715780860481111561094d5761094c6108eb565b5b600185161561095c5780820291505b808102905061096a8561091a565b9450610931565b94509492505050565b60008261098a5760019050610a46565b816109985760009050610a46565b81600181146109ae57600281146109b8576109e7565b6001915050610a46565b60ff8411156109ca576109c96108eb565b5b8360020a9150848211156109e1576109e06108eb565b5b50610a46565b5060208310610133831016604e8410600b8410161715610a1c5782820a905083811115610a1757610a166108eb565b5b610a46565b610a298484846001610927565b92509050818404811115610a4057610a3f6108eb565b5b81810290505b9392505050565b600060ff82169050919050565b6000610a65826106e7565b9150610a7083610a4d565b9250610a9d7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff848461097a565b905092915050565b6000610ab0826106e7565b9150610abb836106e7565b9250828202610ac9816106e7565b91508282048414831517610ae057610adf6108eb565b5b5092915050565b6000819050919050565b610afa81610ae7565b82525050565b610b09816106e7565b82525050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610b3a82610b0f565b9050919050565b610b4a81610b2f565b82525050565b600060a082019050610b656000830188610af1565b610b726020830187610af1565b610b7f6040830186610af1565b610b8c6060830185610b00565b610b996080830184610b41565b9695505050505050565b6000602082019050610bb86000830184610b41565b92915050565b600082825260208201905092915050565b60005b83811015610bed578082015181840152602081019050610bd2565b60008484015250505050565b6000601f19601f8301169050919050565b6000610c15826105c9565b610c1f8185610bbe565b9350610c2f818560208601610bcf565b610c3881610bf9565b840191505092915050565b60006020820190508181036000830152610c5d8184610c0a565b905092915050565b600081519050919050565b6000819050602082019050919050565b6000610c8c8251610ae7565b80915050919050565b6000610ca082610c65565b82610caa84610c70565b9050610cb581610c80565b92506020821015610cf557610cf07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83602003600802610688565b831692505b5050919050565b6000610d07826106e7565b9150610d12836106e7565b9250828201905080821115610d2a57610d296108eb565b5b92915050565b6000606082019050610d456000830186610b41565b610d526020830185610b00565b610d5f6040830184610b00565b949350505050565b6000602082019050610d7c6000830184610b00565b92915050565b60805160a05160c05160e051610100516101205161014051611c17610ddc6000396000610a3e01526000610a0301526000610f5301526000610f32015260006108fe015260006109540152600061097d0152611c176000f3fe608060405234801561001057600080fd5b50600436106100cf5760003560e01c806370a082311161008c57806395d89b411161006657806395d89b4114610230578063a9059cbb1461024e578063d505accf1461027e578063dd62ed3e1461029a576100cf565b806370a08231146101ac5780637ecebe00146101dc57806384b0196e1461020c576100cf565b806306fdde03146100d4578063095ea7b3146100f257806318160ddd1461012257806323b872dd14610140578063313ce567146101705780633644e5151461018e575b600080fd5b6100dc6102ca565b6040516100e99190611440565b60405180910390f35b61010c600480360381019061010791906114fb565b61035c565b6040516101199190611556565b60405180910390f35b61012a61037f565b6040516101379190611580565b60405180910390f35b61015a6004803603810190610155919061159b565b610389565b6040516101679190611556565b60405180910390f35b6101786103b8565b604051610185919061160a565b60405180910390f35b6101966103c1565b6040516101a3919061163e565b60405180910390f35b6101c660048036038101906101c19190611659565b6103d0565b6040516101d39190611580565b60405180910390f35b6101f660048036038101906101f19190611659565b610418565b6040516102039190611580565b60405180910390f35b61021461042a565b604051610227979695949392919061178e565b60405180910390f35b6102386104d4565b6040516102459190611440565b60405180910390f35b610268600480360381019061026391906114fb565b610566565b6040516102759190611556565b60405180910390f35b6102986004803603810190610293919061186a565b610589565b005b6102b460048036038101906102af919061190c565b6106d1565b6040516102c19190611580565b60405180910390f35b6060600380546102d99061197b565b80601f01602080910402602001604051908101604052809291908181526020018280546103059061197b565b80156103525780601f1061032757610100808354040283529160200191610352565b820191906000526020600020905b81548152906001019060200180831161033557829003601f168201915b5050505050905090565b600080610367610758565b9050610374818585610760565b600191505092915050565b6000600254905090565b600080610394610758565b90506103a1858285610772565b6103ac858585610806565b60019150509392505050565b60006012905090565b60006103cb6108fa565b905090565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000610423826109b1565b9050919050565b60006060806000806000606061043e6109fa565b610446610a35565b46306000801b600067ffffffffffffffff811115610467576104666119ac565b5b6040519080825280602002602001820160405280156104955781602001602082028036833780820191505090505b507f0f00000000000000000000000000000000000000000000000000000000000000959493929190965096509650965096509650965090919293949596565b6060600480546104e39061197b565b80601f016020809104026020016040519081016040528092919081815260200182805461050f9061197b565b801561055c5780601f106105315761010080835404028352916020019161055c565b820191906000526020600020905b81548152906001019060200180831161053f57829003601f168201915b5050505050905090565b600080610571610758565b905061057e818585610806565b600191505092915050565b834211156105ce57836040517f627913020000000000000000000000000000000000000000000000000000000081526004016105c59190611580565b60405180910390fd5b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886105fd8c610a70565b89604051602001610613969594939291906119db565b604051602081830303815290604052805190602001209050600061063682610ac7565b9050600061064682878787610ae1565b90508973ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146106ba57808a6040517f4b800e460000000000000000000000000000000000000000000000000000000081526004016106b1929190611a3c565b60405180910390fd5b6106c58a8a8a610760565b50505050505050505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b61076d8383836001610b11565b505050565b600061077e84846106d1565b90507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811461080057818110156107f0578281836040517ffb8f41b20000000000000000000000000000000000000000000000000000000081526004016107e793929190611a65565b60405180910390fd5b6107ff84848484036000610b11565b5b50505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036108785760006040517f96c6fd1e00000000000000000000000000000000000000000000000000000000815260040161086f9190611a9c565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16036108ea5760006040517fec442f050000000000000000000000000000000000000000000000000000000081526004016108e19190611a9c565b60405180910390fd5b6108f5838383610ce8565b505050565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff1614801561097657507f000000000000000000000000000000000000000000000000000000000000000046145b156109a3577f000000000000000000000000000000000000000000000000000000000000000090506109ae565b6109ab610f0d565b90505b90565b6000600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6060610a3060057f0000000000000000000000000000000000000000000000000000000000000000610fa390919063ffffffff16565b905090565b6060610a6b60067f0000000000000000000000000000000000000000000000000000000000000000610fa390919063ffffffff16565b905090565b6000600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000815480929190600101919050559050919050565b6000610ada610ad46108fa565b83611053565b9050919050565b600080600080610af388888888611094565b925092509250610b038282611188565b829350505050949350505050565b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1603610b835760006040517fe602df05000000000000000000000000000000000000000000000000000000008152600401610b7a9190611a9c565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610bf55760006040517f94280d62000000000000000000000000000000000000000000000000000000008152600401610bec9190611a9c565b60405180910390fd5b81600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508015610ce2578273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92584604051610cd99190611580565b60405180910390a35b50505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610d3a578060026000828254610d2e9190611ae6565b92505081905550610e0d565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610dc6578381836040517fe450d38c000000000000000000000000000000000000000000000000000000008152600401610dbd93929190611a65565b60405180910390fd5b8181036000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610e565780600260008282540392505081905550610ea3565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055505b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051610f009190611580565b60405180910390a3505050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000004630604051602001610f88959493929190611b1a565b60405160208183030381529060405280519060200120905090565b606060ff60001b8314610fc057610fb9836112ec565b905061104d565b818054610fcc9061197b565b80601f0160208091040260200160405190810160405280929190818152602001828054610ff89061197b565b80156110455780601f1061101a57610100808354040283529160200191611045565b820191906000526020600020905b81548152906001019060200180831161102857829003601f168201915b505050505090505b92915050565b60006040517f190100000000000000000000000000000000000000000000000000000000000081528360028201528260228201526042812091505092915050565b60008060007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08460001c11156110d457600060038592509250925061117e565b6000600188888888604051600081526020016040526040516110f99493929190611b6d565b6020604051602081039080840390855afa15801561111b573d6000803e3d6000fd5b505050602060405103519050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361116f57600060016000801b9350935093505061117e565b8060008060001b935093509350505b9450945094915050565b6000600381111561119c5761119b611bb2565b5b8260038111156111af576111ae611bb2565b5b03156112e857600160038111156111c9576111c8611bb2565b5b8260038111156111dc576111db611bb2565b5b03611213576040517ff645eedf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002600381111561122757611226611bb2565b5b82600381111561123a57611239611bb2565b5b0361127f578060001c6040517ffce698f70000000000000000000000000000000000000000000000000000000081526004016112769190611580565b60405180910390fd5b60038081111561129257611291611bb2565b5b8260038111156112a5576112a4611bb2565b5b036112e757806040517fd78bce0c0000000000000000000000000000000000000000000000000000000081526004016112de919061163e565b60405180910390fd5b5b5050565b606060006112f983611360565b90506000602067ffffffffffffffff811115611318576113176119ac565b5b6040519080825280601f01601f19166020018201604052801561134a5781602001600182028036833780820191505090505b5090508181528360208201528092505050919050565b60008060ff8360001c169050601f8111156113a7576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80915050919050565b600081519050919050565b600082825260208201905092915050565b60005b838110156113ea5780820151818401526020810190506113cf565b60008484015250505050565b6000601f19601f8301169050919050565b6000611412826113b0565b61141c81856113bb565b935061142c8185602086016113cc565b611435816113f6565b840191505092915050565b6000602082019050818103600083015261145a8184611407565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061149282611467565b9050919050565b6114a281611487565b81146114ad57600080fd5b50565b6000813590506114bf81611499565b92915050565b6000819050919050565b6114d8816114c5565b81146114e357600080fd5b50565b6000813590506114f5816114cf565b92915050565b6000806040838503121561151257611511611462565b5b6000611520858286016114b0565b9250506020611531858286016114e6565b9150509250929050565b60008115159050919050565b6115508161153b565b82525050565b600060208201905061156b6000830184611547565b92915050565b61157a816114c5565b82525050565b60006020820190506115956000830184611571565b92915050565b6000806000606084860312156115b4576115b3611462565b5b60006115c2868287016114b0565b93505060206115d3868287016114b0565b92505060406115e4868287016114e6565b9150509250925092565b600060ff82169050919050565b611604816115ee565b82525050565b600060208201905061161f60008301846115fb565b92915050565b6000819050919050565b61163881611625565b82525050565b6000602082019050611653600083018461162f565b92915050565b60006020828403121561166f5761166e611462565b5b600061167d848285016114b0565b91505092915050565b60007fff0000000000000000000000000000000000000000000000000000000000000082169050919050565b6116bb81611686565b82525050565b6116ca81611487565b82525050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b611705816114c5565b82525050565b600061171783836116fc565b60208301905092915050565b6000602082019050919050565b600061173b826116d0565b61174581856116db565b9350611750836116ec565b8060005b83811015611781578151611768888261170b565b975061177383611723565b925050600181019050611754565b5085935050505092915050565b600060e0820190506117a3600083018a6116b2565b81810360208301526117b58189611407565b905081810360408301526117c98188611407565b90506117d86060830187611571565b6117e560808301866116c1565b6117f260a083018561162f565b81810360c08301526118048184611730565b905098975050505050505050565b61181b816115ee565b811461182657600080fd5b50565b60008135905061183881611812565b92915050565b61184781611625565b811461185257600080fd5b50565b6000813590506118648161183e565b92915050565b600080600080600080600060e0888a03121561188957611888611462565b5b60006118978a828b016114b0565b97505060206118a88a828b016114b0565b96505060406118b98a828b016114e6565b95505060606118ca8a828b016114e6565b94505060806118db8a828b01611829565b93505060a06118ec8a828b01611855565b92505060c06118fd8a828b01611855565b91505092959891949750929550565b6000806040838503121561192357611922611462565b5b6000611931858286016114b0565b9250506020611942858286016114b0565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061199357607f821691505b6020821081036119a6576119a561194c565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600060c0820190506119f0600083018961162f565b6119fd60208301886116c1565b611a0a60408301876116c1565b611a176060830186611571565b611a246080830185611571565b611a3160a0830184611571565b979650505050505050565b6000604082019050611a5160008301856116c1565b611a5e60208301846116c1565b9392505050565b6000606082019050611a7a60008301866116c1565b611a876020830185611571565b611a946040830184611571565b949350505050565b6000602082019050611ab160008301846116c1565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000611af1826114c5565b9150611afc836114c5565b9250828201905080821115611b1457611b13611ab7565b5b92915050565b600060a082019050611b2f600083018861162f565b611b3c602083018761162f565b611b49604083018661162f565b611b566060830185611571565b611b6360808301846116c1565b9695505050505050565b6000608082019050611b82600083018761162f565b611b8f60208301866115fb565b611b9c604083018561162f565b611ba9606083018461162f565b95945050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fdfea2646970667358221220e1ce3e885df35ba0ba99e0ab184fabd9f7a70f26eabb59549127c63c28b9e6ce64736f6c634300081b0033", + "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c806370a082311161008c57806395d89b411161006657806395d89b4114610230578063a9059cbb1461024e578063d505accf1461027e578063dd62ed3e1461029a576100cf565b806370a08231146101ac5780637ecebe00146101dc57806384b0196e1461020c576100cf565b806306fdde03146100d4578063095ea7b3146100f257806318160ddd1461012257806323b872dd14610140578063313ce567146101705780633644e5151461018e575b600080fd5b6100dc6102ca565b6040516100e99190611440565b60405180910390f35b61010c600480360381019061010791906114fb565b61035c565b6040516101199190611556565b60405180910390f35b61012a61037f565b6040516101379190611580565b60405180910390f35b61015a6004803603810190610155919061159b565b610389565b6040516101679190611556565b60405180910390f35b6101786103b8565b604051610185919061160a565b60405180910390f35b6101966103c1565b6040516101a3919061163e565b60405180910390f35b6101c660048036038101906101c19190611659565b6103d0565b6040516101d39190611580565b60405180910390f35b6101f660048036038101906101f19190611659565b610418565b6040516102039190611580565b60405180910390f35b61021461042a565b604051610227979695949392919061178e565b60405180910390f35b6102386104d4565b6040516102459190611440565b60405180910390f35b610268600480360381019061026391906114fb565b610566565b6040516102759190611556565b60405180910390f35b6102986004803603810190610293919061186a565b610589565b005b6102b460048036038101906102af919061190c565b6106d1565b6040516102c19190611580565b60405180910390f35b6060600380546102d99061197b565b80601f01602080910402602001604051908101604052809291908181526020018280546103059061197b565b80156103525780601f1061032757610100808354040283529160200191610352565b820191906000526020600020905b81548152906001019060200180831161033557829003601f168201915b5050505050905090565b600080610367610758565b9050610374818585610760565b600191505092915050565b6000600254905090565b600080610394610758565b90506103a1858285610772565b6103ac858585610806565b60019150509392505050565b60006012905090565b60006103cb6108fa565b905090565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000610423826109b1565b9050919050565b60006060806000806000606061043e6109fa565b610446610a35565b46306000801b600067ffffffffffffffff811115610467576104666119ac565b5b6040519080825280602002602001820160405280156104955781602001602082028036833780820191505090505b507f0f00000000000000000000000000000000000000000000000000000000000000959493929190965096509650965096509650965090919293949596565b6060600480546104e39061197b565b80601f016020809104026020016040519081016040528092919081815260200182805461050f9061197b565b801561055c5780601f106105315761010080835404028352916020019161055c565b820191906000526020600020905b81548152906001019060200180831161053f57829003601f168201915b5050505050905090565b600080610571610758565b905061057e818585610806565b600191505092915050565b834211156105ce57836040517f627913020000000000000000000000000000000000000000000000000000000081526004016105c59190611580565b60405180910390fd5b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886105fd8c610a70565b89604051602001610613969594939291906119db565b604051602081830303815290604052805190602001209050600061063682610ac7565b9050600061064682878787610ae1565b90508973ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146106ba57808a6040517f4b800e460000000000000000000000000000000000000000000000000000000081526004016106b1929190611a3c565b60405180910390fd5b6106c58a8a8a610760565b50505050505050505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b61076d8383836001610b11565b505050565b600061077e84846106d1565b90507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811461080057818110156107f0578281836040517ffb8f41b20000000000000000000000000000000000000000000000000000000081526004016107e793929190611a65565b60405180910390fd5b6107ff84848484036000610b11565b5b50505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036108785760006040517f96c6fd1e00000000000000000000000000000000000000000000000000000000815260040161086f9190611a9c565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16036108ea5760006040517fec442f050000000000000000000000000000000000000000000000000000000081526004016108e19190611a9c565b60405180910390fd5b6108f5838383610ce8565b505050565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff1614801561097657507f000000000000000000000000000000000000000000000000000000000000000046145b156109a3577f000000000000000000000000000000000000000000000000000000000000000090506109ae565b6109ab610f0d565b90505b90565b6000600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6060610a3060057f0000000000000000000000000000000000000000000000000000000000000000610fa390919063ffffffff16565b905090565b6060610a6b60067f0000000000000000000000000000000000000000000000000000000000000000610fa390919063ffffffff16565b905090565b6000600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000815480929190600101919050559050919050565b6000610ada610ad46108fa565b83611053565b9050919050565b600080600080610af388888888611094565b925092509250610b038282611188565b829350505050949350505050565b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1603610b835760006040517fe602df05000000000000000000000000000000000000000000000000000000008152600401610b7a9190611a9c565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610bf55760006040517f94280d62000000000000000000000000000000000000000000000000000000008152600401610bec9190611a9c565b60405180910390fd5b81600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508015610ce2578273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92584604051610cd99190611580565b60405180910390a35b50505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610d3a578060026000828254610d2e9190611ae6565b92505081905550610e0d565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610dc6578381836040517fe450d38c000000000000000000000000000000000000000000000000000000008152600401610dbd93929190611a65565b60405180910390fd5b8181036000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610e565780600260008282540392505081905550610ea3565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055505b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051610f009190611580565b60405180910390a3505050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000004630604051602001610f88959493929190611b1a565b60405160208183030381529060405280519060200120905090565b606060ff60001b8314610fc057610fb9836112ec565b905061104d565b818054610fcc9061197b565b80601f0160208091040260200160405190810160405280929190818152602001828054610ff89061197b565b80156110455780601f1061101a57610100808354040283529160200191611045565b820191906000526020600020905b81548152906001019060200180831161102857829003601f168201915b505050505090505b92915050565b60006040517f190100000000000000000000000000000000000000000000000000000000000081528360028201528260228201526042812091505092915050565b60008060007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08460001c11156110d457600060038592509250925061117e565b6000600188888888604051600081526020016040526040516110f99493929190611b6d565b6020604051602081039080840390855afa15801561111b573d6000803e3d6000fd5b505050602060405103519050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361116f57600060016000801b9350935093505061117e565b8060008060001b935093509350505b9450945094915050565b6000600381111561119c5761119b611bb2565b5b8260038111156111af576111ae611bb2565b5b03156112e857600160038111156111c9576111c8611bb2565b5b8260038111156111dc576111db611bb2565b5b03611213576040517ff645eedf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002600381111561122757611226611bb2565b5b82600381111561123a57611239611bb2565b5b0361127f578060001c6040517ffce698f70000000000000000000000000000000000000000000000000000000081526004016112769190611580565b60405180910390fd5b60038081111561129257611291611bb2565b5b8260038111156112a5576112a4611bb2565b5b036112e757806040517fd78bce0c0000000000000000000000000000000000000000000000000000000081526004016112de919061163e565b60405180910390fd5b5b5050565b606060006112f983611360565b90506000602067ffffffffffffffff811115611318576113176119ac565b5b6040519080825280601f01601f19166020018201604052801561134a5781602001600182028036833780820191505090505b5090508181528360208201528092505050919050565b60008060ff8360001c169050601f8111156113a7576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80915050919050565b600081519050919050565b600082825260208201905092915050565b60005b838110156113ea5780820151818401526020810190506113cf565b60008484015250505050565b6000601f19601f8301169050919050565b6000611412826113b0565b61141c81856113bb565b935061142c8185602086016113cc565b611435816113f6565b840191505092915050565b6000602082019050818103600083015261145a8184611407565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061149282611467565b9050919050565b6114a281611487565b81146114ad57600080fd5b50565b6000813590506114bf81611499565b92915050565b6000819050919050565b6114d8816114c5565b81146114e357600080fd5b50565b6000813590506114f5816114cf565b92915050565b6000806040838503121561151257611511611462565b5b6000611520858286016114b0565b9250506020611531858286016114e6565b9150509250929050565b60008115159050919050565b6115508161153b565b82525050565b600060208201905061156b6000830184611547565b92915050565b61157a816114c5565b82525050565b60006020820190506115956000830184611571565b92915050565b6000806000606084860312156115b4576115b3611462565b5b60006115c2868287016114b0565b93505060206115d3868287016114b0565b92505060406115e4868287016114e6565b9150509250925092565b600060ff82169050919050565b611604816115ee565b82525050565b600060208201905061161f60008301846115fb565b92915050565b6000819050919050565b61163881611625565b82525050565b6000602082019050611653600083018461162f565b92915050565b60006020828403121561166f5761166e611462565b5b600061167d848285016114b0565b91505092915050565b60007fff0000000000000000000000000000000000000000000000000000000000000082169050919050565b6116bb81611686565b82525050565b6116ca81611487565b82525050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b611705816114c5565b82525050565b600061171783836116fc565b60208301905092915050565b6000602082019050919050565b600061173b826116d0565b61174581856116db565b9350611750836116ec565b8060005b83811015611781578151611768888261170b565b975061177383611723565b925050600181019050611754565b5085935050505092915050565b600060e0820190506117a3600083018a6116b2565b81810360208301526117b58189611407565b905081810360408301526117c98188611407565b90506117d86060830187611571565b6117e560808301866116c1565b6117f260a083018561162f565b81810360c08301526118048184611730565b905098975050505050505050565b61181b816115ee565b811461182657600080fd5b50565b60008135905061183881611812565b92915050565b61184781611625565b811461185257600080fd5b50565b6000813590506118648161183e565b92915050565b600080600080600080600060e0888a03121561188957611888611462565b5b60006118978a828b016114b0565b97505060206118a88a828b016114b0565b96505060406118b98a828b016114e6565b95505060606118ca8a828b016114e6565b94505060806118db8a828b01611829565b93505060a06118ec8a828b01611855565b92505060c06118fd8a828b01611855565b91505092959891949750929550565b6000806040838503121561192357611922611462565b5b6000611931858286016114b0565b9250506020611942858286016114b0565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061199357607f821691505b6020821081036119a6576119a561194c565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600060c0820190506119f0600083018961162f565b6119fd60208301886116c1565b611a0a60408301876116c1565b611a176060830186611571565b611a246080830185611571565b611a3160a0830184611571565b979650505050505050565b6000604082019050611a5160008301856116c1565b611a5e60208301846116c1565b9392505050565b6000606082019050611a7a60008301866116c1565b611a876020830185611571565b611a946040830184611571565b949350505050565b6000602082019050611ab160008301846116c1565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000611af1826114c5565b9150611afc836114c5565b9250828201905080821115611b1457611b13611ab7565b5b92915050565b600060a082019050611b2f600083018861162f565b611b3c602083018761162f565b611b49604083018661162f565b611b566060830185611571565b611b6360808301846116c1565b9695505050505050565b6000608082019050611b82600083018761162f565b611b8f60208301866115fb565b611b9c604083018561162f565b611ba9606083018461162f565b95945050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fdfea2646970667358221220e1ce3e885df35ba0ba99e0ab184fabd9f7a70f26eabb59549127c63c28b9e6ce64736f6c634300081b0033", + "linkReferences": {}, + "deployedLinkReferences": {} +} diff --git a/networks/ethereum/devnet/README.md b/networks/ethereum/devnet/README.md index 3e29f52b..29f8f3cd 100644 --- a/networks/ethereum/devnet/README.md +++ b/networks/ethereum/devnet/README.md @@ -5,9 +5,19 @@ npx ganache \ --account="0x0000000000000000000000000000000000000000000000000000000000000001,1000000000000000000" \ --account="0x0000000000000000000000000000000000000000000000000000000000000002,1000000000000000000" ``` +or +``` +yarn run-ganache +``` -2. run test under networks/ethereum: +2. run test under networks/ethereum: ``` yarn test:devnet ``` + +3. for ethers test, run under networks/ethereum: + +``` +yarn test:ethers +``` \ No newline at end of file diff --git a/networks/ethereum/devnet/__tests__/ethers.test.ts b/networks/ethereum/devnet/__tests__/ethers.test.ts new file mode 100644 index 00000000..b73f6e13 --- /dev/null +++ b/networks/ethereum/devnet/__tests__/ethers.test.ts @@ -0,0 +1,71 @@ +import { ethers } from 'ethers'; +import fs from 'fs'; +import path from 'path'; + +describe('ETH Transfer Test', () => { + let provider: ethers.JsonRpcProvider; + let walletSender: ethers.Wallet; + let walletReceiver: ethers.Wallet; + let usdtAddress: string; + let usdtContract: ethers.Contract; + + const privSender = '0x' + '0'.repeat(63) + '1'; + const privReceiver = '0x' + '0'.repeat(63) + '2'; + + beforeAll(async () => { + provider = new ethers.JsonRpcProvider('http://127.0.0.1:8545'); + // provider = new ethers.BrowserProvider(window.ethereum) // if in browser + + walletSender = new ethers.Wallet(privSender, provider); + // walletSender = await provider.getSigner() // if in browser. like the offline signer in keplr cosmos + + walletReceiver = new ethers.Wallet(privReceiver, provider); // only used to receive token + + const usdtArtifactPath = path.join(__dirname, '../../contracts/usdt/contract.json'); + const usdtArtifact = JSON.parse(fs.readFileSync(usdtArtifactPath, 'utf8')); + const { abi, bytecode } = usdtArtifact; + const UsdtFactory = new ethers.ContractFactory(abi as any, bytecode, walletSender); + usdtContract = await UsdtFactory.deploy() as ethers.Contract; + await usdtContract.waitForDeployment(); + usdtAddress = await usdtContract.getAddress(); + + }); + + it('should transfer ETH from wallet0 to wallet1 and check balances', async () => { + const initialBalanceSender = await provider.getBalance(walletSender.address); + const initialBalanceReceiver = await provider.getBalance(walletReceiver.address); + + const amountToSend = ethers.parseEther('0.01'); + + const tx = await walletSender.sendTransaction({ + to: walletReceiver.address, + value: amountToSend, + }); + + await tx.wait(); + + const finalBalanceSender = await provider.getBalance(walletSender.address); + const finalBalanceReceiver = await provider.getBalance(walletReceiver.address); + + expect(finalBalanceSender).toBeLessThan(initialBalanceSender); + expect(finalBalanceReceiver).toBeGreaterThan(initialBalanceReceiver); + expect(finalBalanceReceiver).toEqual(initialBalanceReceiver + amountToSend); + }); + + it('should transfer USDT from sender to receiver', async () => { + const decimals = 6; + const amountToSend = ethers.parseUnits('100', decimals); + + const initialSenderBalance = await usdtContract.balanceOf(walletSender.address); + const initialReceiverBalance = await usdtContract.balanceOf(walletReceiver.address); + + const tx = await (usdtContract as any).connect(walletSender).transfer(walletReceiver.address, amountToSend); + await tx.wait(); + + const finalSenderBalance = await usdtContract.balanceOf(walletSender.address); + const finalReceiverBalance = await usdtContract.balanceOf(walletReceiver.address); + + expect(finalSenderBalance).toEqual(initialSenderBalance - amountToSend); + expect(finalReceiverBalance).toEqual(initialReceiverBalance + amountToSend); + }); +}); diff --git a/networks/ethereum/devnet/__tests__/send.test.ts b/networks/ethereum/devnet/__tests__/send.test.ts deleted file mode 100644 index c82ffb3c..00000000 --- a/networks/ethereum/devnet/__tests__/send.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { ethers } from 'ethers'; - -describe('ETH Transfer Test', () => { - let provider: ethers.JsonRpcProvider; - let wallet0: ethers.Wallet; - let wallet1: ethers.Wallet; - - const privateKey0 = '0x0000000000000000000000000000000000000000000000000000000000000001'; - const privateKey1 = '0x0000000000000000000000000000000000000000000000000000000000000002'; - - beforeAll(async () => { - provider = new ethers.JsonRpcProvider('http://127.0.0.1:8545'); - // provider = new ethers.BrowserProvider(window.ethereum) // if in browser - - wallet0 = new ethers.Wallet(privateKey0, provider); - // wallet0 = await provider.getSigner() // if in browser. like the offline signer in keplr cosmos - - wallet1 = new ethers.Wallet(privateKey1, provider); // only used to receive token - }); - - it('should transfer ETH from wallet0 to wallet1 and check balances', async () => { - const initialBalance0 = await provider.getBalance(wallet0.address); - const initialBalance1 = await provider.getBalance(wallet1.address); - - const amountToSend = ethers.parseEther('0.01'); - - const tx = await wallet0.sendTransaction({ - to: wallet1.address, - value: amountToSend, - }); - - await tx.wait(); - - const finalBalance0 = await provider.getBalance(wallet0.address); - const finalBalance1 = await provider.getBalance(wallet1.address); - - expect(finalBalance0).toBeLessThan(initialBalance0); - expect(finalBalance1).toBeGreaterThan(initialBalance1); - expect(finalBalance1).toEqual(initialBalance1 + amountToSend); - }); -}); \ No newline at end of file diff --git a/networks/ethereum/devnet/run-ganache.sh b/networks/ethereum/devnet/run-ganache.sh new file mode 100644 index 00000000..6e38b4a7 --- /dev/null +++ b/networks/ethereum/devnet/run-ganache.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +npx ganache \ + --account="0x0000000000000000000000000000000000000000000000000000000000000001,1000000000000000000" \ + --account="0x0000000000000000000000000000000000000000000000000000000000000002,1000000000000000000" \ No newline at end of file diff --git a/networks/ethereum/package.json b/networks/ethereum/package.json index 3e9fabce..754d53b0 100644 --- a/networks/ethereum/package.json +++ b/networks/ethereum/package.json @@ -23,7 +23,10 @@ "build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy", "build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy", "lint": "eslint . --fix", - "test:devnet": "npx jest --preset ts-jest devnet/__tests__/send.icjs.test.ts" + "test:devnet": "npx jest --preset ts-jest devnet/__tests__/send.icjs.test.ts", + "test:ethers": "npx jest --preset ts-jest devnet/__tests__/ethers.test.ts", + "run-ganache": "bash devnet/run-ganache.sh", + "deploy:usdt": "ts-node contracts/usdt/deploy.ts" }, "dependencies": { "@ethersproject/bignumber": "^5.7.0", @@ -40,4 +43,4 @@ "blockchain", "transaction" ] -} +} \ No newline at end of file From 623dbbfe9734e5a51946156ba6ed98fd18a651fd Mon Sep 17 00:00:00 2001 From: Eason Smith Date: Fri, 13 Dec 2024 15:07:37 +0800 Subject: [PATCH 2/2] update package.json --- networks/ethereum/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/networks/ethereum/package.json b/networks/ethereum/package.json index 754d53b0..f5aa32f0 100644 --- a/networks/ethereum/package.json +++ b/networks/ethereum/package.json @@ -25,8 +25,7 @@ "lint": "eslint . --fix", "test:devnet": "npx jest --preset ts-jest devnet/__tests__/send.icjs.test.ts", "test:ethers": "npx jest --preset ts-jest devnet/__tests__/ethers.test.ts", - "run-ganache": "bash devnet/run-ganache.sh", - "deploy:usdt": "ts-node contracts/usdt/deploy.ts" + "run-ganache": "bash devnet/run-ganache.sh" }, "dependencies": { "@ethersproject/bignumber": "^5.7.0",