Skip to content

Commit

Permalink
Bump sei-cosmos to integrate with DeliverTxHook change (#1900)
Browse files Browse the repository at this point in the history
* Bump sei-cosmos to integrate with DeliverTxHook change

* fix tests

* bump sei-cosmos

* fund integration tests accounts more

* exp

* fix integration tests
  • Loading branch information
codchen authored Oct 22, 2024
1 parent fc9a0bd commit a45b5ca
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 32 deletions.
8 changes: 3 additions & 5 deletions app/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ type AllowanceResponse struct {
Expires json.RawMessage `json:"expires"`
}

func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.Tx, checksum [32]byte, response abci.ResponseDeliverTx) {
if response.Code > 0 {
return
}
func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.Tx, checksum [32]byte, response sdk.DeliverTxHookInput) {
// hooks will only be called if DeliverTx is successful
wasmEvents := GetEventsOfType(response, wasmtypes.WasmModuleEventType)
if len(wasmEvents) == 0 {
return
Expand Down Expand Up @@ -283,7 +281,7 @@ func (app *App) GetEvmAddressAttribute(ctx sdk.Context, event abci.Event, attrib
return EmptyHash
}

func GetEventsOfType(rdtx abci.ResponseDeliverTx, ty string) (res []abci.Event) {
func GetEventsOfType(rdtx sdk.DeliverTxHookInput, ty string) (res []abci.Event) {
for _, event := range rdtx.Events {
if event.Type == ty {
res = append(res, event)
Expand Down
14 changes: 7 additions & 7 deletions contracts/test/ERC721toCW721PointerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe("ERC721 to CW721 Pointer", function () {
describe("write", function(){
it("approve", async function () {
const blockNumber = await ethers.provider.getBlockNumber();
const approvedTxResp = await pointerAcc0.approve(accounts[1].evmAddress, 2)
const approvedTxResp = await pointerAcc0.approve(accounts[1].evmAddress, 2, { gasPrice: ethers.parseUnits('100', 'gwei') })
await approvedTxResp.wait()
const approved = await pointerAcc0.getApproved(2);
expect(approved).to.equal(accounts[1].evmAddress);
Expand Down Expand Up @@ -113,14 +113,14 @@ describe("ERC721 to CW721 Pointer", function () {
});

it("cannot approve token you don't own", async function () {
await expect(pointerAcc0.approve(accounts[1].evmAddress, 1)).to.be.reverted;
await expect(pointerAcc0.approve(accounts[1].evmAddress, 1, { gasPrice: ethers.parseUnits('100', 'gwei') })).to.be.reverted;
});

it("transfer from", async function () {
// accounts[0] should transfer token id 2 to accounts[1]
await mine(pointerAcc0.approve(accounts[1].evmAddress, 2));
const blockNumber = await ethers.provider.getBlockNumber();
transferTxResp = await pointerAcc1.transferFrom(accounts[0].evmAddress, accounts[1].evmAddress, 2);
transferTxResp = await pointerAcc1.transferFrom(accounts[0].evmAddress, accounts[1].evmAddress, 2, { gasPrice: ethers.parseUnits('100', 'gwei') });
const receipt = await transferTxResp.wait();
const filter = {
fromBlock: '0x' + blockNumber.toString(16),
Expand All @@ -147,9 +147,9 @@ describe("ERC721 to CW721 Pointer", function () {
expect(balance1).to.equal(2);

// do same for eth_getBlockReceipts and sei_getBlockReceipts
const ethBlockReceipts = await ethers.provider.send('eth_getBlockReceipts', ['0x' + blockNumber.toString(16)]);
const ethBlockReceipts = await ethers.provider.send('eth_getBlockReceipts', ['0x' + receipt.blockNumber.toString(16)]);
expect(ethBlockReceipts.length).to.equal(1);
const seiBlockReceipts = await ethers.provider.send('sei_getBlockReceipts', ['0x' + blockNumber.toString(16)]);
const seiBlockReceipts = await ethers.provider.send('sei_getBlockReceipts', ['0x' + receipt.blockNumber.toString(16)]);
expect(seiBlockReceipts.length).to.equal(1);

const ethTx = await ethers.provider.send('eth_getTransactionReceipt', [receipt.hash]);
Expand All @@ -165,11 +165,11 @@ describe("ERC721 to CW721 Pointer", function () {
});

it("cannot transfer token you don't own", async function () {
await expect(pointerAcc0.transferFrom(accounts[0].evmAddress, accounts[1].evmAddress, 3)).to.be.reverted;
await expect(pointerAcc0.transferFrom(accounts[0].evmAddress, accounts[1].evmAddress, 3, { gasPrice: ethers.parseUnits('100', 'gwei') })).to.be.reverted;
});

it("set approval for all", async function () {
const setApprovalForAllTxResp = await pointerAcc0.setApprovalForAll(accounts[1].evmAddress, true);
const setApprovalForAllTxResp = await pointerAcc0.setApprovalForAll(accounts[1].evmAddress, true, { gasPrice: ethers.parseUnits('100', 'gwei') });
await setApprovalForAllTxResp.wait();
await expect(setApprovalForAllTxResp)
.to.emit(pointerAcc0, 'ApprovalForAll')
Expand Down
30 changes: 15 additions & 15 deletions contracts/test/EVMCompatabilityTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe("EVM Test", function () {

describe("Contract Factory", function() {
it("should deploy a second contract from createToken", async function () {
const txResponse = await evmTester.createToken("TestToken", "TTK");
const txResponse = await evmTester.createToken("TestToken", "TTK", { gasPrice: ethers.parseUnits('100', 'gwei') });
const testerAddress = await evmTester.getAddress();
const receipt = await txResponse.wait();
const newTokenAddress = receipt.logs[0].address;
Expand Down Expand Up @@ -215,7 +215,7 @@ describe("EVM Test", function () {
it("Should set the address correctly and emit an event", async function () {
// Call setAddress
await delay()
const txResponse = await evmTester.setAddressVar();
const txResponse = await evmTester.setAddressVar({ gasPrice: ethers.parseUnits('100', 'gwei') });
await txResponse.wait(); // Wait for the transaction to be mined
await expect(txResponse)
.to.emit(evmTester, 'AddressSet')
Expand All @@ -225,7 +225,7 @@ describe("EVM Test", function () {
it("Should set the bool correctly and emit an event", async function () {
// Call setBoolVar
await delay()
const txResponse = await evmTester.setBoolVar(true);
const txResponse = await evmTester.setBoolVar(true, { gasPrice: ethers.parseUnits('100', 'gwei') });
await txResponse.wait(); // Wait for the transaction to be mined

debug(JSON.stringify(txResponse))
Expand All @@ -241,7 +241,7 @@ describe("EVM Test", function () {
it("Should set the uint256 correctly and emit an event", async function () {
// Call setBoolVar
await delay()
const txResponse = await evmTester.setUint256Var(12345);
const txResponse = await evmTester.setUint256Var(12345, { gasPrice: ethers.parseUnits('100', 'gwei') });
await txResponse.wait(); // Wait for the transaction to be mined

debug(JSON.stringify(txResponse))
Expand Down Expand Up @@ -279,7 +279,7 @@ describe("EVM Test", function () {

it("Should trace a call with timestamp", async function () {
await delay()
const txResponse = await evmTester.setTimestamp();
const txResponse = await evmTester.setTimestamp({ gasPrice: ethers.parseUnits('100', 'gwei') });
const receipt = await txResponse.wait(); // Wait for the transaction to be mined

// get the timestamp that was saved off during setTimestamp()
Expand Down Expand Up @@ -315,7 +315,7 @@ describe("EVM Test", function () {

it("Should set the string correctly and emit an event", async function () {
await delay()
const txResponse = await evmTester.setStringVar("test");
const txResponse = await evmTester.setStringVar("test", { gasPrice: ethers.parseUnits('100', 'gwei') });
const receipt = await txResponse.wait(); // Wait for the transaction to be mined

const cosmosTx = await getCosmosTx(ethers.provider, receipt.hash)
Expand All @@ -332,7 +332,7 @@ describe("EVM Test", function () {

it("Should set the bytes correctly and emit an event", async function () {
await delay()
const txResponse = await evmTester.setBytesVar(ethers.toUtf8Bytes("test"));
const txResponse = await evmTester.setBytesVar(ethers.toUtf8Bytes("test"), { gasPrice: ethers.parseUnits('100', 'gwei') });
await txResponse.wait();

await expect(txResponse)
Expand All @@ -347,7 +347,7 @@ describe("EVM Test", function () {

await delay()
// Send the transaction and wait for it to be confirmed
const txResponse = await evmTester.setBalance(owner.address, testAmount);
const txResponse = await evmTester.setBalance(owner.address, testAmount, { gasPrice: ethers.parseUnits('100', 'gwei') });
await txResponse.wait();
await delay()
// Now check the balance
Expand All @@ -358,7 +358,7 @@ describe("EVM Test", function () {
it("Should store and retrieve a private var correctly", async function () {
const testAmount = 12345;
await delay()
const txResponse = await evmTester.storeData(testAmount);
const txResponse = await evmTester.storeData(testAmount, { gasPrice: ethers.parseUnits('100', 'gwei') });
await txResponse.wait(); // Wait for the transaction to be mined
await delay()
const retrievedAmount = await evmTester.retrieveData();
Expand All @@ -379,7 +379,7 @@ describe("EVM Test", function () {

describe("Assembly", function(){
it("Should add numbers correctly", async function () {
expect(await evmTester.addNumbers(10, 20)).to.equal(30);
expect(await evmTester.addNumbers(10, 20, { gasPrice: ethers.parseUnits('100', 'gwei') })).to.equal(30);
});

it("Should return the current balance of the contract", async function () {
Expand All @@ -392,7 +392,7 @@ describe("EVM Test", function () {
it("Should return correct value from readFromStorage(index)", async function () {
const testAmount = 12345;
await delay()
const txResponse = await evmTester.storeData(testAmount);
const txResponse = await evmTester.storeData(testAmount, { gasPrice: ethers.parseUnits('100', 'gwei') });
await delay()
await txResponse.wait(); // Wait for the transaction to be mined

Expand Down Expand Up @@ -697,7 +697,7 @@ describe("EVM Test", function () {
const numberOfEvents = 5;

// check receipt
const txResponse = await evmTester.emitMultipleLogs(numberOfEvents);
const txResponse = await evmTester.emitMultipleLogs(numberOfEvents, { gasPrice: ethers.parseUnits('100', 'gwei') });
const receipt = await txResponse.wait();
expect(receipt.logs.length).to.equal(numberOfEvents)
for(let i=0; i<receipt.logs.length; i++) {
Expand All @@ -721,7 +721,7 @@ describe("EVM Test", function () {
it("Should fetch logs for a specific event", async function () {
// Emit an event by making a transaction
const blockNumber = await ethers.provider.getBlockNumber();
const txResponse = await evmTester.setBoolVar(true);
const txResponse = await evmTester.setBoolVar(true, { gasPrice: ethers.parseUnits('100', 'gwei') });
await txResponse.wait();

// Create a filter to get logs
Expand Down Expand Up @@ -753,7 +753,7 @@ describe("EVM Test", function () {
ethers.provider.on(filter, listener);

// Trigger the event
const txResponse = await evmTester.setBoolVar(false);
const txResponse = await evmTester.setBoolVar(false, { gasPrice: ethers.parseUnits('100', 'gwei') });
await txResponse.wait();
});

Expand Down Expand Up @@ -808,7 +808,7 @@ describe("EVM Test", function () {

// Emit an event by making a transaction
for (let i = 0; i < numTxs; i++) {
const txResponse = await evmTester.emitDummyEvent("test", i);
const txResponse = await evmTester.emitDummyEvent("test", i, { gasPrice: ethers.parseUnits('100', 'gwei') });
await txResponse.wait();
}
blockEnd = await ethers.provider.getBlockNumber();
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ async function getEvmTx(provider, cosmosTxHash) {
return await provider.send("sei_getEvmTx", [cosmosTxHash])
}

async function fundAddress(addr, amount="10000000000000000000") {
async function fundAddress(addr, amount="1000000000000000000000") {
const result = await evmSend(addr, adminKeyName, amount)
await delay()
return result
}

async function evmSend(addr, fromKey, amount="100000000000000000000000") {
async function evmSend(addr, fromKey, amount="10000000000000000000000000") {
const output = await execute(`seid tx evm send ${addr} ${amount} --from ${fromKey} -b block -y`);
return output.replace(/.*0x/, "0x").trim()
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ require (
replace (
github.com/CosmWasm/wasmd => github.com/sei-protocol/sei-wasmd v0.2.4
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.3.37-0.20240923023912-aa7a702d42cc
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.3.39
github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.2.0
github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.2
github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-23
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1347,8 +1347,8 @@ github.com/sei-protocol/go-ethereum v1.13.5-sei-23 h1:rkgeOHC56QTco4mIyGd6cZHtlo
github.com/sei-protocol/go-ethereum v1.13.5-sei-23/go.mod h1:kcRZmuzRn1lVejiFNTz4l4W7imnpq1bDAnuKS/RyhbQ=
github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQpIbXDA=
github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8=
github.com/sei-protocol/sei-cosmos v0.3.37-0.20240923023912-aa7a702d42cc h1:srWLbsoS0NYBIl8OjZOFuPmIeqf+fJTkfsK39MmG3+k=
github.com/sei-protocol/sei-cosmos v0.3.37-0.20240923023912-aa7a702d42cc/go.mod h1:ZwWxF/69WlcLEn4BzVjPPToTFkE2sjPanU8PNNyKoOk=
github.com/sei-protocol/sei-cosmos v0.3.39 h1:EaAoJNyN11MJCkgZG5D92UGXLy0X2NAPz0HltOHEBxk=
github.com/sei-protocol/sei-cosmos v0.3.39/go.mod h1:ZwWxF/69WlcLEn4BzVjPPToTFkE2sjPanU8PNNyKoOk=
github.com/sei-protocol/sei-db v0.0.44 h1:HMgcyDTQlmXdJysHJxmIo66EKeXn1CSQT9qXDnxjJgI=
github.com/sei-protocol/sei-db v0.0.44/go.mod h1:F/ZKZA8HJPcUzSZPA8yt6pfwlGriJ4RDR4eHKSGLStI=
github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I=
Expand Down

0 comments on commit a45b5ca

Please sign in to comment.